Skip to main content

synthesize

synthesize(
model: SerializedModel | BaseQFunc,
auto_show: bool = False,
constraints: Constraints | None = None,
preferences: Preferences | None = None
) -> QuantumProgram
Synthesize a model with the Classiq engine to receive a quantum program. More details Parameters: Returns:

show

show(
quantum_program: QuantumProgram,
display_url: bool = True
) -> None
Displays the interactive representation of the quantum program in the Classiq IDE. Parameters:

assign_parameters

assign_parameters(
quantum_program: QuantumProgram,
parameters: ExecutionParams
) -> QuantumProgram
Assign parameters to a parametric quantum program. Parameters: Returns:
  • Type: QuantumProgram
  • The quantum program after assigning parameters.

export

export(
quantum_program: QuantumProgram,
target_language: TargetLanguage | None = TargetLanguage.QASM2,
transpilation_config: TranspilationConfig | FaultTolerantTranspilationConfig | None | Literal[True] = None
) -> str
Export a quantum program as a circuit string in the requested target language. Non-angle runtime parameters (e.g. integers that affect circuit structure such as repeat counts) must be assigned first using :func:assign_parameters. Parameters: Returns:
  • Type: str
  • The exported circuit code as a string.

get_circuit_metrics

get_circuit_metrics(
quantum_program: QuantumProgram
) -> CircuitMetrics
Get the logical resource estimation (depth and gate counts) of a quantum program. For parametric programs, depth and gate counts may be returned as symbolic string expressions (e.g. "n + 1") instead of integers. Parameters: Returns:
  • Type: CircuitMetrics
  • The logical depth and gate counts of the quantum program.

get_transpiled_circuit_metrics

get_transpiled_circuit_metrics(
quantum_program: QuantumProgram
) -> ProgramData
Get the hardware resource estimation (depth and gate counts) of a transpiled quantum program. Parameters: Returns:
  • Type: ProgramData
  • The hardware data and circuit metrics (depth and gate counts) of the transpiled program.

QuantumProgram

Methods:

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

has_compiled_qmod

has_compiled_qmod: bool

compiled_qmod

compiled_qmod: Model | None

qasm

qasm: Code | None

save_results

save_results(
self: ,
filename: str | Path | None = None
) -> None
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:

raise_warnings

raise_warnings(
self:
) -> None
Raises all warnings that were collected during synthesis. Parameters:

Preferences

Preferences for synthesizing a quantum circuit. Methods: Attributes:

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). ')

qasm3

qasm3: bool | None = pydantic.Field(None, description='Output OpenQASM 3.0 instead of OpenQASM 2.0. Relevant only for the qasmandtranspiled_circuit.qasmattributes ofGeneratedCircuit.')

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)

compatibility_mode

compatibility_mode: bool = pydantic.Field(default=False)

backend_preferences

backend_preferences: BackendPreferences | None

set_preferences

set_preferences(
serialized_model: SerializedModel,
preferences: Preferences | None = None,
kwargs: Any = 
) -> SerializedModel
Overrides the preferences of a (serialized) model and returns the updated model. Parameters: Returns:
  • Type: SerializedModel
  • The updated model with the new preferences applied.

set_execution_preferences

set_execution_preferences(
serialized_model: SerializedModel,
execution_preferences: ExecutionPreferences | None = None,
kwargs: Any = 
) -> SerializedModel
Overrides the execution preferences of a (serialized) model and returns the updated model. Parameters:

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:

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

set_constraints(
serialized_model: SerializedModel,
constraints: Constraints | None = None,
kwargs: Any = 
) -> SerializedModel
Overrides the constraints of a (serialized) model and returns the updated model. Parameters: Returns:
  • Type: SerializedModel
  • The updated model with the new constraints applied.

create_model

create_model(
entry_point: QFunc | GenerativeQFunc,
constraints: Constraints | None = None,
execution_preferences: ExecutionPreferences | None = None,
preferences: Preferences | None = None,
classical_execution_function: CFunc | None = None,
out_file: str | None = None
) -> SerializedModel
Create a serialized model from a given Qmod entry function and additional parameters. Parameters: Returns:
  • Type: SerializedModel
  • A serialized model. Functions:

write_qmod

write_qmod(
model: SerializedModel | QFunc | GenerativeQFunc,
name: str,
directory: Path | None = None,
decimal_precision: int = DEFAULT_DECIMAL_PRECISION,
symbolic_only: bool = True
) -> None
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: Returns:
  • Type: None

qasm_to_qmod

qasm_to_qmod(
qasm: str,
qmod_format: QmodFormat
) -> str
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: Returns:
  • Type: str
  • The decompiled Qmod program