Writing out and exporting
Writing out
OpenSquirrel's native tongue is cQASM. Accordingly, it is straightforward to write out a circuit, since the string representation of a circuit is a cQASM string.
Use the Python built-in methods str
or print
to obtain the cQASM string of the circuit.
In the case of the example program that we compiled in the previous section, we simply do the following to write out the circuit:
Exporting
Alternatively, it is possible to export the circuit to a
different format.
This can be done by using the export
method with the desired format as an input argument.
For instance, if we want to export our circuit to
cQASM 1.0 (given by the export format CQASM_V1
) we write the following:
from opensquirrel.passes.exporter import ExportFormat
exported_circuit = circuit.export(fmt=ExportFormat.CQASM_V1)
This uses the cQASMv1 exporter to export the circuit to a cQASM 1.0 string.
print(exported_circuit) # Compiled program in terms of cQASM 1.0
Note that there may be language constructs that do not have a straightforward translation from cQASM to the chosen format. For example, cQASM 1.0 does not support the declaration of bit registers. Consequently, any information regarding bit registers and variables will be lost-in-translation, e.g., in cQASM 1.0, measurement outcomes cannot be written to a specific bit register variable even if this has been done in the original cQASM program.