Synthesis Preferences¶
You can modify these synthesis process preferences:
In the example below, the chosen output format includes 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.
{
"function_library": {
"functions": [
{
"name": "main",
"logic_flow": [{
"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"],
"custom_hardware_settings":{
"basis_gates":["cx", "cp", "sx", "rz", "x"]
}
}
}
from classiq import Model
from classiq.model import (
CustomHardwareSettings,
Preferences,
)
from classiq.builtin_functions.state_preparation import Metrics
from classiq.builtin_functions.range_types import NonNegativeFloatRange
from classiq.builtin_functions import QFT, StatePreparation
custom_hardware_settings = CustomHardwareSettings(
basis_gates=["cx", "cp", "sx", "rz", "x"]
)
preferences = Preferences(
output_format=["qasm", "qsharp"], custom_hardware_settings=custom_hardware_settings
)
model = 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(
probabilities=probabilities,
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)
circuit = model.synthesize()
circuit.show()
print(circuit.qsharp)
Output Formats¶
The Classiq platform provides different ways to format the output of generated circuits. 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 incircuit.qasm
.- By default, the Classiq platform uses OpenQASM 2.0. To use OpenQASM 3.0 instead, set the
qasm3
field of the preferences toTrue
.
- By default, the Classiq platform uses OpenQASM 2.0. To use OpenQASM 3.0 instead, set the
"qsharp"
- Q#. The qsharp circuit is incircuit.qsharp
."qir"
- Microsoft's QIR. The QIR circuit is incircuit.qir
."ionq"
- IonQ Json format is found incircuit.ionq
."cirq_json"
- Cirq Json format is found incircuit.cirq_json
."qasm_cirq_compatible"
- OpenQASM 2.0 is compatible with Cirq, which is incircuit.qasm_cirq_compatible
.
Timeouts¶
The Classiq platform offers two timeouts: the generation timeout and the optimization timeout. Both timeouts are specified in a whole number of seconds.
The generation timeout, timeout_seconds
, governs the entire synthesis process.
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.