Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself
Classiq’s synthesis engine takes a high-level model written in the Qmod language, and compiles it into an executable gate-level circuit. When mapping high-level functionality to concrete circuits, there may be many different but equivalent possible implementations that reflect tradeoffs in the overall depth, width, gate counts, etc. For example, implementing a multi-controlled-not operation can be shallower in gates given more auxiliary qubits. Choosing the best implementation for a specific operation instance depends on the overall constraints and objectives, as well as the specific structure of the quantum program. Let’s look at a simple model, and use Classiq’s synthesis engine to compile it given different optimization objectives.
First, let’s synthesize to optimize on circuit depth, i.e. to minimize the longest path formed by gates in the circuit, which determines the required coherence time.
We can inspect the resulting circuit using Classiq’s web visualization:
Output:
The resulting width, depth, and gate count appear in the Program Info tab of the quantum program on the platform. You can also get them in code, using get_circuit_metrics:
Output:
Now, let’s synthesize to optimize width, i.e. to minimize the number of qubits used.
Inspect the resulting circuit:
Output:
Output:
As expected, the width-optimized program uses fewer qubits than the depth-optimized one but is deeper. These are the metrics of the synthesized program. To get the metrics of the circuit after transpiling it to the gate set and connectivity defined in your synthesis preferences (by default, a broad set of standard gates with full connectivity), use get_transpiled_circuit_metrics.

Visualization

When opening a quantum program using the show command, the visualization provides details regarding the quantum circuit’s structure. Key characteristics, such as gate count, qubit usage, and circuit depth, are displayed. The visualization is organized according to the building blocks used during the quantum program construction. These blocks represent modular components or routines in your quantum algorithm. By clicking on the ”+” sign on a block, you can expand it to reveal the underlying quantum gates, making it easier to inspect, debug, or understand the algorithm’s logic at both high and low levels. This can be seen in the following figure: the left panel represents a high-level view showing the quantum blocks used in the algorithm, such as hadamard_transform and assign x**2 + 1, while the right panel shows an expanded view of the assign block, revealing the underlying gates, such as PHASE operations and quantum Fourier transform blocks. Quantum Program Visualization

Exporting and Sharing

In addition to visualizing a quantum program, the tool lets you export it in multiple formats, enabling integration with other tools and workflows:
  • Circuit languages: QASM, transpiled QASM, QIR, Cirq JSON, and Q#, for running the circuit on other quantum simulators, hardware platforms, and frameworks.
The same conversions are available in the SDK through the export function.
  • Quantum program files: QPROG and JSON, which store the synthesized quantum program itself rather than a circuit in another language.
  • Images: JPEG for a graphical image of the circuit, and LaTeX for a high-quality, pictorial representation ready for inclusion in LaTeX files.
To download every format at once, choose All Formats. To share a quantum program, copy its URL from your browser and send it to anyone who wants to view the circuit, with no login required.

Exercise

Create your own main function and synthesize it with different constraints. Note that OptimizationParameter is only one kind of configuration possible. Classiq synthesis engine also supports a rigid max_width constraint.