Modeling
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:
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 | 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 | 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:
Name | Type | Description |
---|---|---|
SerializedModel |
SerializedModel
|
A serialized model. |
Raises:
Type | Description |
---|---|
ClassiqError
|
If the entry point function is not named 'main'. |
write_qmod
Functions:
Name | Description |
---|---|
prepare_write_qmod_model |
|
write_qmod |
Creates a native Qmod file from a serialized model and outputs the synthesis options (Preferences and Constraints) to a file. |
prepare_write_qmod_model
prepare_write_qmod_model(
model: SerializedModel | QFunc | GenerativeQFunc,
symbolic_only: bool,
) -> Model
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:
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 | Description |
---|---|
None
|
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:
Name | Type | Description | Default |
---|---|---|---|
qasm
|
str
|
QASM 2 or QASM 3 code |
required |
qmod_format
|
QmodFormat
|
The requested output format |
required |
Returns:
Type | Description |
---|---|
str
|
The decompiled Qmod program |