Analyze - Classiq Visualization Tool
Once you have designed the quantum algorithm and sythesized the quantum program, the next natural step is to analyze the quantum program to check if and how the underlying quantum circuit implements the desired quantum algorithm. The Classiq visualization tool explores the quantum circuit interactively on different level of functional hierarchies, and extracts crucial information about it.
Ways to access the Classiq visualization tool:
- From the IDE, in the
Model
tab, clickSynthesize
:
- From the Python SDK, by running the
show(quantum_program)
command:
from classiq import *
@qfunc
def main(x: Output[QNum], y: Output[QNum]):
allocate(4, x)
hadamard_transform(x) # creates a uniform superposition
y |= x**2 + 1
quantum_program = synthesize(create_model(main))
show(quantum_program)
Opening: https://platform.classiq.io/circuit/f729dc29-9aa2-49f6-907f-c284445c4dc8?version=0.41.0.dev39%2B79c8fd0855
qfunc main(output x: qnum, output y: qnum) {
allocate(4, x);
hadamard_transform(x);
y = (x ** 2) + 1;
}
- By directly uploading a circuit or quantum program to the IDE:
Below covers key aspects of the visualization tool. For a full list of the features and possibilities of the tool, access the reference manual.
Navigating
The high-level functional design approach of Classiq enables analyzing quantum circuits on different levels of functionality. You can view your circuit only on the functional building block level, e.g., hadamard_transform
and Arithmetic
in the example below, or you can zoom in to the actual gate-level implementations:
In addition to the plus and minus buttons, you can also use the navigation map button to navigate through your circuit:
This is especially helpful for large circuits.
Quantum Program Information
On the left of the visualization tool is information about the quantum program such as the circuit depth, circuit width, and gate count. As shown in the picture below, it is divided into information about the quantum program and the transpiled quantum circuit:
The quantum program is the output of the synthesis engine and it contains the circuit implementation that preserves the functional logic of your algorithm. This information correlates to the circuit shown in the center of the window. For the example covered in this tutorial, the final functional building block in the Power
block and the first functional building block in the Adder
block should cancel each other out, because applying them consecutively is equivalent to not applying them at all (these blocks are the quantum Fourier transform and its inverse):
On the other hand, the transpiled circuit is the circuit that is sent for execution, which is further optimized by eliminating functional blocks that have no influence on the circuit such as the two blocks that cancel each other. The transpiled circuit contains only the set of gates defined by the optimization preferences. View the transpiled circuit by downloading it as Transpiled QASM
and uploading it to the visualization tool:
Download the quantum program in your selected format (QASM, JPEG, JSON, LaTeX code, etc.) by clicking the download button as illustrated in the image above.
Adapting Names
To keep track of your quantum circuits while you are working, rename them with meaningful names by double clicking the circuit tab, typing the new name, and confirming your choice.
You can rename the blocks in the circuit by double clicking them and typing new names.
After analyzing the quantum circuit, you can adapt the model or execute the circuit on a simulator or real hardware. Continue to the Execute section to understand how to do that.
Verify Your Understanding - Recommended Exercise
Open the above example in the IDE and from the Quantum Program tab, export the circuit as a LaTeX file. View it in a LaTeX Editor (it is recommended to use Overleaf - a free, easy to use online LaTeX editor).
write_qmod(create_model(main), "analyze")