sf.save

save(f, prog, ir='blackbird', **kwargs)[source]

Saves a quantum program to a Blackbird .xbb or an XIR .xir file.

Example:

prog = sf.Program(3)

with prog.context as q:
    ops.Sgate(0.543) | q[1]
    ops.BSgate(0.6, 0.1) | (q[2], q[0])
    ops.MeasureFock() | q

sf.save("program1.xbb", prog, ir="blackbird")

This will create the following Blackbird file:

>>> f = open("program1.xbb").read()
>>> print(f)
name None
version 1.0

Sgate(0.543, 0.0) | 1
BSgate(0.6, 0.1) | [2, 0]
MeasureFock() | [0, 1, 2]
Parameters
  • f (Union[file, str, pathlib.Path]) – File or filename to which the data is saved. If file is a file-object, then the filename is unchanged. If file is a string or Path, a .xbb extension will be appended to the file name if it does not already have one.

  • prog (Program) – Strawberry Fields program

  • ir (str) – Intermediate representation language to use. Can be either “blackbird” or “xir”.

Keyword Arguments

add_decl (bool) – Whether gate and output declarations should be added to the XIR program. Default is False.

Return type

None