Skip to content

Synthesis Preferences

You can modify these synthesis process preferences:

In this example, the chosen output format includes both Q# and OpenQASM. Specific basis gates are selected for the synthesis: controlled not, controlled phase, square root of not, Z-rotation, and not gates.

  "functions": [
      "name": "main",
      "body": [{
          "function": "StatePreparation",
          "function_params": {
            "probabilities": [0.5, 0.1, 0.2, 0.005, 0.015, 0.12, 0.035, 0.025],
            "error_metric": { "KL": { "upper_bound": 0.3 }}
          "outputs": "sp_out"
          "function": "QFT",
          "function_params": {
            "num_qubits": 3
          "inputs": "sp_out"
  "preferences": {
    "output_format": ["qsharp", "qasm"],
      "basis_gates":["cx", "cp", "sx", "rz", "x"]
from classiq import Model, synthesize, show, set_preferences, GeneratedCircuit

from classiq.model import (
from classiq.builtin_functions.state_preparation import Metrics
from classiq.builtin_functions.range_types import NonNegativeFloatRange

from classiq.builtin_functions import QFT, StatePreparation

model = Model()

# Alternatively, we could set the model preferences later with:
# model.preferences = preferences

num_qubits = 3

probabilities = (0.5, 0.1, 0.2, 0.005, 0.015, 0.12, 0.035, 0.025)
sp_params = StatePreparation(
    error_metric={Metrics.KL: NonNegativeFloatRange(upper_bound=0.3)},
x = model.StatePreparation(sp_params)["OUT"]

qft_params = QFT(num_qubits=num_qubits)
model.QFT(qft_params, in_wires=x)

custom_hardware_settings = CustomHardwareSettings(
    basis_gates=["cx", "cp", "sx", "rz", "x"]
preferences = Preferences(
    output_format=["qasm", "qsharp"], custom_hardware_settings=custom_hardware_settings

serialized_model = model.get_model()
serialized_model = set_preferences(serialized_model, preferences)
qprog = synthesize(serialized_model)


Output Formats

The Classiq platform provides different ways to format the output of synthesized quantum programs. You can choose multiple output formats.

  • In the SDK, you can print or save the desired output format after synthesizing.
  • In the IDE, you can download the desired output format after synthesizing.

The output options:

  • "qasm" - OpenQASM. The qasm circuit is in circuit.qasm, where circuit = GeneratedCircuit.from_qprog(qprog).
    • By default, the Classiq platform uses OpenQASM 2.0. To use OpenQASM 3.0 instead, set the qasm3 field of the preferences to True.
  • "qsharp" - Q#. The qsharp circuit is in circuit.qsharp.
  • "qir" - Microsoft's QIR. The QIR circuit is in circuit.qir.
  • "ionq" - IonQ Json format is in circuit.ionq.
  • "cirq_json" - Cirq Json format is in circuit.cirq_json.
  • "qasm_cirq_compatible" - OpenQASM 2.0 is compatible with Cirq, which is in circuit.qasm_cirq_compatible.


The Classiq platform offers two timeouts:

  • timeout_seconds – The generation timeout governs the entire synthesis process.
  • optimization_timeout_seconds – Amongst other tasks, the synthesis engine performs optimization (see Optimization Parameter), which may take a long time to complete. Therefore, to limit the amount of time the engine spends optimizing, set optimization_timeout_seconds. If no optimization occurs (for example, if you did not specify an optimization parameter), this timeout has no effect. When the optimization timeout is reached, the synthesis engine returns the best solution found so far. If the engine does not find a solution within that time, it issues a message.

You can specify both timeouts. Just make sure that the optimization timeout is smaller than the generation timeout. Both timeouts are specified in a whole number of seconds.

Toggling Quantum Program Visualization Support

The Classiq platform allows users to toggle quantum program visualization support. This flag is intended for advanced usage of creating a synthesis-execution flow only, skipping the payloads required for displaying the quantum program:

  • support_circuit_visualization - When the flag is set to True (default), the quantum program can be visualized using the show command and generated in the IDE. See Quantum Program Visualization Tool.

Setting this flag to False can potentially improve synthesis-execution flow speeds. Such quantum programs are only supported in the SDK. See Executor.