> ## Documentation Index
> Fetch the complete documentation index at: https://prod-mint.classiq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Synthesis

### synthesize

<pre><code>synthesize(
model: SerializedModel | BaseQFunc,
auto\_show: bool = False,
constraints: <a href="#constraints">Constraints</a> | None = None,
preferences: <a href="#preferences">Preferences</a> | None = None
) -> <a href="#quantumprogram">QuantumProgram</a></code></pre>

Synthesize a model with the Classiq engine to receive a quantum program.
[More details](https://docs.classiq.io/latest/sdk-reference/synthesis/#classiq.synthesize)

**Parameters:**

| Name          | Type                                | Description                                                                                                | Default    |
| ------------- | ----------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------- |
| `model`       | `SerializedModel \| BaseQFunc`      | The entry point of the Qmod model - a qfunc named 'main' (or alternatively the output of 'create\_model'). | *required* |
| `auto_show`   | `bool`                              | Whether to 'show' the synthesized model (False by default).                                                | False      |
| `constraints` | [Constraints](#constraints) \| None | Constraints for the synthesis of the model. See Constraints (Optional).                                    | None       |
| `preferences` | [Preferences](#preferences) \| None | Preferences for the synthesis of the model. See Preferences (Optional).                                    | None       |

**Returns:**

* **Type:** [QuantumProgram](#quantumprogram)
* Quantum program. (See: QuantumProgram)

### show

<pre><code>show(
quantum\_program: <a href="#quantumprogram">QuantumProgram</a>,
display\_url: bool = True
) -> None</code></pre>

Displays the interactive representation of the quantum program in the Classiq IDE.

**Parameters:**

| Name              | Type                              | Description                          | Default    |
| ----------------- | --------------------------------- | ------------------------------------ | ---------- |
| `quantum_program` | [QuantumProgram](#quantumprogram) | The quantum program to be displayed. | *required* |
| `display_url`     | `bool`                            | Whether to print the url             | True       |

### QuantumProgram

**Methods:**

| Name                                  | Description                                               |
| ------------------------------------- | --------------------------------------------------------- |
| [to\_base\_program](#to_base_program) |                                                           |
| [to\_program](#to_program)            |                                                           |
| [save\_results](#save_results)        | Saves quantum program results as json into a file.        |
| [get\_debug\_info](#get_debug_info)   |                                                           |
| [raise\_warnings](#raise_warnings)    | Raises all warnings that were collected during synthesis. |

### hardware\_data

`hardware_data: SynthesisHardwareData`

### data

`data: GeneratedCircuitData`

### model

`model: ExecutionModel`

### transpiled\_circuit

`transpiled_circuit: TranspiledCircuitData | None = pydantic.Field(default=None)`

### creation\_time

`creation_time: str = pydantic.Field(default_factory=_get_formatted_utc_current_time)`

### compressed\_debug\_info

`compressed_debug_info: bytes | None = pydantic.Field(default=None)`

### program\_id

`program_id: str = pydantic.Field(default_factory=get_uuid_as_str)`

### execution\_primitives\_input

`execution_primitives_input: PrimitivesInput | None = pydantic.Field(default=None)`

### synthesis\_warnings

`synthesis_warnings: list[str] | None = pydantic.Field(default=None)`

### compressed\_compiled\_qmod

`compressed_compiled_qmod: bytes | None = pydantic.Field(default=None)`

### program\_circuit

`program_circuit: CircuitCodeInterface`

### compiled\_qmod

`compiled_qmod: Model | None`

#### save\_results

<pre><code>save\_results(
self: ,
filename: str | Path | None = None
) -> None</code></pre>

Saves quantum program results as json into a file.
Parameters:
filename (Union\[str, Path]): Optional, path + filename of file.
If filename supplied add `.json` suffix.
Returns:
None

**Parameters:**

| Name       | Type                  | Description | Default    |
| ---------- | --------------------- | ----------- | ---------- |
| `self`     | \`\`                  |             | *required* |
| `filename` | `str \| Path \| None` |             | None       |

#### raise\_warnings

<pre><code>raise\_warnings(
self:
) -> None</code></pre>

Raises all warnings that were collected during synthesis.

**Parameters:**

| Name   | Type | Description | Default    |
| ------ | ---- | ----------- | ---------- |
| `self` | \`\` |             | *required* |

### Preferences

Preferences for synthesizing a quantum circuit.

**Methods:**

| Name                                                                                                         | Description |
| ------------------------------------------------------------------------------------------------------------ | ----------- |
| [optimization\_timeout\_less\_than\_generation\_timeout](#optimization_timeout_less_than_generation_timeout) |             |
| [make\_output\_format\_list](#make_output_format_list)                                                       |             |
| [validate\_output\_format](#validate_output_format)                                                          |             |
| [validate\_backend\_name](#validate_backend_name)                                                            |             |
| [validate\_backend](#validate_backend)                                                                       |             |

**Attributes:**

| Name                            | Type                     | Description                                                                                                                                                                                                                                                        |
| ------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `machine_precision`             | `int`                    | Specifies the precision used for quantum operations. Defaults to `DEFAULT_MACHINE_PRECISION`.                                                                                                                                                                      |
| `backend_service_provider`      | `str`                    | The provider company or cloud service for the requested backend. Defaults to `None`.                                                                                                                                                                               |
| `backend_name`                  | `str`                    | The name of the requested backend or target. Defaults to `None`.                                                                                                                                                                                                   |
| `custom_hardware_settings`      | `CustomHardwareSettings` | Defines custom hardware settings for optimization. This field is ignored if backend preferences are specified.                                                                                                                                                     |
| `debug_mode`                    | `bool`                   | If `True`, debug information is added to the synthesized result, potentially slowing down the synthesis. Useful for executing interactive algorithms. Defaults to `True`.                                                                                          |
| `optimization_level`            | `OptimizationLevel)`     | The optimization level used during synthesis (0-3);                                                                                                                                                                                                                |
| `output_format`                 | `List[QuantumFormat]`    | Lists the output format(s) for the quantum circuit. Defaults to `[QuantumFormat.QASM]`. `QuantumFormat` Options: - QASM = "qasm" - QSHARP = "qsharp" - QIR = "qir" - IONQ = "ionq" - CIRQ\_JSON = "cirq\_json" - QASM\_CIRQ\_COMPATIBLE = "qasm\_cirq\_compatible" |
| `pretty_qasm`                   | `bool`                   | If `True`, formats OpenQASM 2 outputs with line breaks inside gate declarations, improving readability. Defaults to `True`.                                                                                                                                        |
| `qasm3`                         | `Optional[bool]`         | If `True`, outputs OpenQASM 3.0 in addition to 2.0, applicable to relevant attributes in `GeneratedCircuit`. Defaults to `None`.                                                                                                                                   |
| `transpilation_option`          | `TranspilationOption`    | Sets the transpilation option to optimize the circuit. Defaults to `AUTO_OPTIMIZE`. See `TranspilationOption`                                                                                                                                                      |
| `solovay_kitaev_max_iterations` | `Optional[int]`          | Specifies the maximum number of iterations for the Solovay-Kitaev algorithm, if used. Defaults to `None`.                                                                                                                                                          |
| `timeout_seconds`               | `int`                    | Timeout setting for circuit synthesis in seconds. Defaults to `300`.                                                                                                                                                                                               |
| `optimization_timeout_seconds`  | `Optional[int]`          | Specifies the timeout for optimization in seconds, or `None` for no optimization timeout. This will still adhere to the overall synthesis timeout. Defaults to `None`.                                                                                             |
| `random_seed`                   | `int`                    | Random seed for circuit synthesis.                                                                                                                                                                                                                                 |

### machine\_precision

`machine_precision: PydanticMachinePrecision = DEFAULT_MACHINE_PRECISION`

### backend\_service\_provider

`backend_service_provider: Provider | ProviderVendor | str | None = pydantic.Field(default=None, description='Provider company or cloud for the requested backend.')`

### backend\_name

`backend_name: PydanticBackendName | AllBackendsNameByVendor | None = pydantic.Field(default=None, description='Name of the requested backend or target.')`

### custom\_hardware\_settings

`custom_hardware_settings: CustomHardwareSettings = pydantic.Field(default_factory=CustomHardwareSettings, description='Custom hardware settings which will be used during optimization. This field is ignored if backend preferences are given.')`

### debug\_mode

`debug_mode: bool = pydantic.Field(default=True, description='Add debug information to the synthesized result. Setting this option to False can potentially speed up the synthesis, and is recommended for executing iterative algorithms.')`

### synthesize\_all\_separately

`synthesize_all_separately: bool = pydantic.Field(default=False, description='If true, a heuristic is used to determine if a function should be synthesized separately', deprecated=True)`

### optimization\_level

`optimization_level: OptimizationLevel = pydantic.Field(default=(OptimizationLevel.LIGHT), description='The optimization level used during synthesis; determines the trade-off between synthesis speed and the quality of the results')`

### output\_format

`output_format: PydanticConstrainedQuantumFormatList = pydantic.Field(default=[QuantumFormat.QASM], description='The quantum circuit output format(s). ')`

### pretty\_qasm

`pretty_qasm: bool = pydantic.Field(True, description='Prettify the OpenQASM2 outputs (use line breaks inside the gate declarations).')`

### qasm3

`qasm3: bool | None = pydantic.Field(None, description='Output OpenQASM 3.0 instead of OpenQASM 2.0. Relevant only for the `qasm`and`transpiled\_circuit.qasm`attributes of`GeneratedCircuit`.')`

### transpilation\_option

`transpilation_option: TranspilationOption = pydantic.Field(default=(TranspilationOption.AUTO_OPTIMIZE), description='If true, the returned result will contain a transpiled circuit and its depth')`

### solovay\_kitaev\_max\_iterations

`solovay_kitaev_max_iterations: pydantic.PositiveInt | None = pydantic.Field(None, description='Maximum iterations for the Solovay-Kitaev algorithm (if applied).')`

### timeout\_seconds

`timeout_seconds: pydantic.PositiveInt = pydantic.Field(default=300, description='Generation timeout in seconds')`

### optimization\_timeout\_seconds

`optimization_timeout_seconds: pydantic.PositiveInt | None = pydantic.Field(default=None, description='Optimization timeout in seconds, or None for no optimization timeout (will still timeout when the generation timeout is over)')`

### random\_seed

`random_seed: int = pydantic.Field(default_factory=create_random_seed, description='The random seed used for the generation')`

### symbolic\_loops

`symbolic_loops: bool = pydantic.Field(default=False)`

### backend\_preferences

`backend_preferences: BackendPreferences | None`

### set\_preferences

<pre><code>set\_preferences(
serialized\_model: SerializedModel,
preferences: <a href="#preferences">Preferences</a> | None = None,
kwargs: Any = {}
) -> SerializedModel</code></pre>

Overrides the preferences of a (serialized) model and returns the updated model.

**Parameters:**

| Name               | Type                                | Description                                                                      | Default    |
| ------------------ | ----------------------------------- | -------------------------------------------------------------------------------- | ---------- |
| `serialized_model` | `SerializedModel`                   | The model in serialized form.                                                    | *required* |
| `preferences`      | [Preferences](#preferences) \| None | The new preferences to be set for the model. Can be passed as keyword arguments. | None       |
| `kwargs`           | `Any`                               |                                                                                  | {}         |

**Returns:**

* **Type:** `SerializedModel`
* The updated model with the new preferences applied.

### set\_execution\_preferences

<pre><code>set\_execution\_preferences(
serialized\_model: SerializedModel,
execution\_preferences: ExecutionPreferences | None = None,
kwargs: Any = {}
) -> SerializedModel</code></pre>

Overrides the execution preferences of a (serialized) model and returns the updated model.

**Parameters:**

| Name                    | Type                           | Description                                                                                | Default    |
| ----------------------- | ------------------------------ | ------------------------------------------------------------------------------------------ | ---------- |
| `serialized_model`      | `SerializedModel`              | A serialization of the defined model.                                                      | *required* |
| `execution_preferences` | `ExecutionPreferences \| None` | The new execution preferences to be set for the model. Can be passed as keyword arguments. | None       |
| `kwargs`                | `Any`                          |                                                                                            | {}         |

### Constraints

Constraints for the quantum circuit synthesis engine.

This class is used to specify constraints such as maximum width, depth,
gate count, and optimization parameters for the synthesis engine,
guiding the generation of quantum circuits that satisfy these constraints.

**Attributes:**

| Name                     | Type                        | Description                                                                                                                             |
| ------------------------ | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `max_width`              | `int`                       | Maximum number of qubits allowed in the generated quantum circuit. Defaults to `None`.                                                  |
| `optimization_parameter` | `OptimizationParameterType` | Determines if and how the synthesis engine should optimize the solution. Defaults to `NO_OPTIMIZATION`. See `OptimizationParameterType` |

### max\_width

`max_width: pydantic.PositiveInt | None = pydantic.Field(default=None, description='Maximum number of qubits in generated quantum circuit')`

### optimization\_parameter

`optimization_parameter: OptimizationParameterType = pydantic.Field(default=(OptimizationParameter.NO_OPTIMIZATION), description='If set, the synthesis engine optimizes the solution according to that chosen parameter')`

### set\_constraints

<pre><code>set\_constraints(
serialized\_model: SerializedModel,
constraints: <a href="#constraints">Constraints</a> | None = None,
kwargs: Any = {}
) -> SerializedModel</code></pre>

Overrides the constraints of a (serialized) model and returns the updated model.

**Parameters:**

| Name               | Type                                | Description                                                                      | Default    |
| ------------------ | ----------------------------------- | -------------------------------------------------------------------------------- | ---------- |
| `serialized_model` | `SerializedModel`                   | The model in serialized form.                                                    | *required* |
| `constraints`      | [Constraints](#constraints) \| None | The new constraints to be set for the model. Can be passed as keyword arguments. | None       |
| `kwargs`           | `Any`                               |                                                                                  | {}         |

**Returns:**

* **Type:** `SerializedModel`
* The updated model with the new constraints applied.

### create\_model

<pre><code>create\_model(
entry\_point: QFunc | GenerativeQFunc,
constraints: <a href="#constraints">Constraints</a> | None = None,
execution\_preferences: ExecutionPreferences | None = None,
preferences: <a href="#preferences">Preferences</a> | None = None,
classical\_execution\_function: CFunc | None = None,
out\_file: str | None = None
) -> SerializedModel</code></pre>

Create a serialized model from a given Qmod entry function and additional parameters.

**Parameters:**

| Name                           | Type                                | Description                                                                      | Default    |
| ------------------------------ | ----------------------------------- | -------------------------------------------------------------------------------- | ---------- |
| `entry_point`                  | `QFunc \| GenerativeQFunc`          | The entry point function for the model, which must be a QFunc named 'main'.      | *required* |
| `constraints`                  | [Constraints](#constraints) \| None | Constraints for the synthesis of the model. See Constraints (Optional).          | None       |
| `execution_preferences`        | `ExecutionPreferences \| None`      | Preferences for the execution of the model. See ExecutionPreferences (Optional). | None       |
| `preferences`                  | [Preferences](#preferences) \| None | Preferences for the synthesis of the model. See Preferences (Optional).          | None       |
| `classical_execution_function` | `CFunc \| None`                     | A function for the classical execution logic, which must be a CFunc (Optional).  | None       |
| `out_file`                     | `str \| None`                       | File path to write the Qmod model in native Qmod representation to (Optional).   | None       |

**Returns:**

* **Type:** `SerializedModel`
* A serialized model.
  Functions:

| Name         | Description                                                                                                                   |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------- |
| `write_qmod` | Creates a native Qmod file from a serialized model and outputs the synthesis options (Preferences and Constraints) to a file. |

### write\_qmod

<pre><code>write\_qmod(
model: SerializedModel | QFunc | GenerativeQFunc,
name: str,
directory: Path | None = None,
decimal\_precision: int = DEFAULT\_DECIMAL\_PRECISION,
symbolic\_only: bool = True
) -> None</code></pre>

Creates a native Qmod file from a serialized model and outputs the synthesis options (Preferences and Constraints) to a file.
The native Qmod file may be uploaded to the Classiq IDE.

**Parameters:**

| Name                | Type                                          | Description                                                                                                                                          | Default                     |
| ------------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| `model`             | `SerializedModel \| QFunc \| GenerativeQFunc` | The entry point of the Qmod model - a qfunc named 'main' (or alternatively the output of 'create\_model').                                           | *required*                  |
| `name`              | `str`                                         | The name to save the file by.                                                                                                                        | *required*                  |
| `directory`         | `Path \| None`                                | The directory to save the files in. If None, the current working directory is used.                                                                  | None                        |
| `decimal_precision` | `int`                                         | The number of decimal places to use for numbers, set to 4 by default.                                                                                | DEFAULT\_DECIMAL\_PRECISION |
| `symbolic_only`     | `bool`                                        | If True keep function definitions un-expanded and symbolic (note that Qmod functions with parameters of Python types are not supported in this mode) | True                        |

**Returns:**

* **Type:** `None`

### qasm\_to\_qmod

<pre><code>qasm\_to\_qmod(
qasm: str,
qmod\_format: QmodFormat
) -> str</code></pre>

Decompiles QASM to Native/Python Qmod.

Returns Qmod code as a string. Native Qmod can be synthesized in the Classiq IDE,
while Python Qmod can be copy-pasted to a Python file (`.py`) and synthesized by
calling `synthesize(main)`.

**Parameters:**

| Name          | Type         | Description                 | Default    |
| ------------- | ------------ | --------------------------- | ---------- |
| `qasm`        | `str`        | QASM 2 or QASM 3 code       | *required* |
| `qmod_format` | `QmodFormat` | The requested output format | *required* |

**Returns:**

* **Type:** `str`
* The decompiled Qmod program
