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.

from classiq import (
    Output,
    QBit,
    allocate,
    create_model,
    synthesize,
    show,
    set_preferences,
    CustomHardwareSettings,
    Preferences,
    QuantumProgram,
)

from classiq.qmod.quantum_function import QFunc


@QFunc
def main(res: Output[QBit]) -> None:
    allocate(1, res)


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

model = create_model(main)
model = set_preferences(model, preferences)
qprog = synthesize(model)
show(qprog)

print(QuantumProgram.from_qprog(qprog).qsharp)

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 = QuantumProgram.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.

Timeouts

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 Debug Information

The Classiq platform allows users to toggle quantum program debug information:

  • debug_mode - When the flag is set to True (default), the quantum program will contain debug information for enhanced visualization (See Quantum Program Visualization Tool).

Setting this flag to False can potentially decrease the quantum program's size and increase synthesis speeds.