# 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=len(x) + 1,  # 1 for an auxiliary qubit
error_metric={Metrics.KL: NonNegativeFloatRange(upper_bound=0.3)},
)
model_designer.StatePreparation(sp_params, out_wires=x)

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

circuit = model_designer.synthesize()
circuit.show_interactive()


## 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.

## Timeouts¶

Two timeouts are available to the user: the generation timeout and the optimization timeout. Both of these timeouts are specified in a whole number of seconds.

The generation timeout, timeout_seconds, governs the entire synthesis process.

One of the tasks that the synthesis engine performs is optimization (see Optimization Parameter). Optimization can take a long time to complete. Therefore, the user may set optimization_timeout_seconds to limit the amount of time the engine spends optimizing. If no optimization occurs (for example, if the user 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 has not found a solution within that time, we inform the user of that fact.

The user may provide both timeouts, as long as the optimization timeout is strictly less than the generation timeout.