Tutorial
The goal of this tutorial is to convey the basic functionalities of OpenSquirrel. In a nutshell, we will do so by
- creating a circuit by reading/building a quantum program,
- applying compilation passes on the circuit, and
- writing out and exporting the compiled program to various formats.
The diagram below illustrates the basic components of OpenSquirrel. We refer to it in the following sections, where we quickly go through the 3 aforementioned steps.
1. creating a circuit
Note that on the left side of the diagram a quantum program written in the cQASM language can be read-in by the reader, which uses the libQASM parser to generate the circuit. Alternatively, a circuit can be produced by using the programmatic API of OpenSquirrel, given by the circuit builder.
Both approaches result in an instance of a Circuit
, which comprises OpenSquirrel's main entrypoint.
The circuit object contains the attributes of the input quantum program
and stores its statements in an Intermediate Representation (IR).
Check for more details: Creating a circuit
2. applying compilation passes
The user can, subsequently, perform certain actions (or methods) on the circuit
object;
these are (at the moment of writing and in alphabetic order):
- decompose
- export
- map
- merge
- route
- validate
For each of these actions the user will provide an appropriate compilation pass
and potential input arguments.
For instance, to obtain the
McKay decomposition of the circuit,
one would select the McKayDecomposer
and perform the decompose
action on the circuit
object accordingly:
This particular pass does not take any input parameters.
Each compilation pass will take the circuit or IR as input and perform the specified action on it. Ultimately, these actions either validate or make changes to certain properties/components of the circuit, whilst preserving the semantic content of the program.
Order matters
Note that the order in which the various compilation passes are applied will have an impact on the final result. In particular, it will make more sense to validate a result after making any changes. For instance, validating wether the gates in the circuit are part of the (specified) primitive gate set, should be done after decomposition.
Check for more details: Applying compilation passes
3. writing out or exporting the compiled program
After the desired actions have been applied to the circuit, one can decide to either write the compiled program to cQASM using the writer, or export the result to a different format, by selecting one of the available exporters.
The string representation of the circuit
object automatically invokes the writer,
so the following line will return the (compiled) program, i.e. program' , in cQASM:
print()
statement can be used to print the program in cQASM.
If one wishes to export the (compiled) program to, for example,
a quantify-scheduler Schedule
one would do the following,
using the quantify-scheduler exporter:
Check for more details: Writing out and exporting