Skip to content

Synthesis Preferences

The preferences of the synthesis process can be modified by the user, including:

In the example below, the output format is chosen to include both Q# and OpenQASM.

In addition, specific basis gates were selected for the synthesis: controlled not, controlled phase, square-root of not, Z-rotation and not gates.

{
  "logic_flow": [{
      "function": "StatePreparation",
      "function_params": {
        "num_qubits": 4,
        "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": ["qs", "qasm"],
    "custom_hardware_settings":{
      "basis_gates":["cx", "cp", "sx", "rz", "x"]
    }
  }
}
from classiq.interface.generator.model.preferences.preferences import (
    CustomHardwareSettings,
    Preferences,
)
from classiq.interface.generator.state_preparation import Metrics, NonNegativeFloatRange

from classiq import ModelDesigner, QReg
from classiq.builtin_functions import QFT, StatePreparation

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

x = QReg(size=3)

probabilities = (0.5, 0.1, 0.2, 0.005, 0.015, 0.12, 0.035, 0.025)
sp_params = StatePreparation(
    probabilities=probabilities,
    num_qubits=x.size + 1,  # 1 for an auxillary qubit
    error_metric={Metrics.KL: NonNegativeFloatRange(upper_bound=0.3)},
)
model_designer.StatePreparation(sp_params, out_wires=x)

qft_params = QFT(num_qubits=x.size)
model_designer.QFT(qft_params, in_wires=x)

circuit = model_designer.synthesize()
circuit.show()

Output Formats

The Classiq platform provides different possibilities for the output format of generated circuits. The output options are:

  • "qasm" - OpenQASM
    • By default, OpenQASM 2.0 will be used. In order to use OpenQASM 3.0, one can set the qasm3 field of the preferences to True.
  • "qs" - Q#
  • "ll" - Microsoft's QIR
  • "ionq" - IonQ Json format
  • "cirq_json" - Cirq Json format
  • "qasm_cirq_compatible" - OpenQASM 2.0 compatible for Cirq.

Multiple output formats can be chosen.