classiq 0.45.1__py3-none-any.whl → 0.46.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- classiq/__init__.py +0 -1
- classiq/_internals/__init__.py +20 -0
- classiq/_internals/authentication/authentication.py +11 -0
- classiq/analyzer/analyzer.py +12 -10
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +1 -1
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +1 -1
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +1 -1
- classiq/applications/libraries/qmci_library.py +4 -9
- classiq/execution/execution_session.py +68 -7
- classiq/executor.py +14 -2
- classiq/interface/_version.py +1 -1
- classiq/interface/backend/backend_preferences.py +189 -0
- classiq/interface/backend/quantum_backend_providers.py +38 -0
- classiq/interface/debug_info/debug_info.py +22 -2
- classiq/interface/exceptions.py +16 -1
- classiq/interface/executor/execution_preferences.py +18 -0
- classiq/interface/generator/application_apis/chemistry_declarations.py +1 -177
- classiq/interface/generator/application_apis/combinatorial_optimization_declarations.py +0 -12
- classiq/interface/generator/application_apis/finance_declarations.py +8 -43
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -78
- classiq/interface/generator/builtin_api_builder.py +0 -3
- classiq/interface/generator/functions/__init__.py +0 -2
- classiq/interface/generator/functions/builtins/__init__.py +0 -15
- classiq/interface/generator/generated_circuit_data.py +2 -0
- classiq/interface/generator/hardware/hardware_data.py +37 -0
- classiq/interface/generator/model/constraints.py +18 -1
- classiq/interface/generator/model/preferences/preferences.py +53 -1
- classiq/interface/generator/model/quantum_register.py +1 -1
- classiq/interface/generator/quantum_program.py +10 -2
- classiq/interface/generator/transpiler_basis_gates.py +4 -0
- classiq/interface/generator/types/builtin_enum_declarations.py +136 -21
- classiq/interface/generator/types/enum_declaration.py +1 -3
- classiq/interface/generator/types/struct_declaration.py +1 -3
- classiq/interface/hardware.py +5 -0
- classiq/interface/ide/visual_model.py +1 -1
- classiq/interface/model/classical_parameter_declaration.py +6 -0
- classiq/interface/model/inplace_binary_operation.py +0 -14
- classiq/interface/model/model.py +1 -18
- classiq/interface/model/port_declaration.py +4 -2
- classiq/interface/model/quantum_function_declaration.py +19 -6
- classiq/interface/model/quantum_lambda_function.py +11 -1
- classiq/interface/model/quantum_variable_declaration.py +1 -1
- classiq/model_expansions/__init__.py +0 -0
- classiq/model_expansions/atomic_expression_functions_defs.py +250 -0
- classiq/model_expansions/capturing/__init__.py +0 -0
- classiq/model_expansions/capturing/captured_var_manager.py +50 -0
- classiq/model_expansions/capturing/mangling_utils.py +17 -0
- classiq/model_expansions/capturing/propagated_var_stack.py +180 -0
- classiq/model_expansions/closure.py +160 -0
- classiq/model_expansions/debug_flag.py +3 -0
- classiq/model_expansions/evaluators/__init__.py +0 -0
- classiq/model_expansions/evaluators/arg_type_match.py +160 -0
- classiq/model_expansions/evaluators/argument_types.py +42 -0
- classiq/model_expansions/evaluators/classical_expression.py +36 -0
- classiq/model_expansions/evaluators/control.py +144 -0
- classiq/model_expansions/evaluators/parameter_types.py +227 -0
- classiq/model_expansions/evaluators/quantum_type_utils.py +235 -0
- classiq/model_expansions/evaluators/type_type_match.py +90 -0
- classiq/model_expansions/expression_evaluator.py +125 -0
- classiq/model_expansions/expression_renamer.py +76 -0
- classiq/model_expansions/function_builder.py +192 -0
- classiq/model_expansions/generative_functions.py +101 -0
- classiq/model_expansions/interpreter.py +365 -0
- classiq/model_expansions/model_tables.py +105 -0
- classiq/model_expansions/quantum_operations/__init__.py +19 -0
- classiq/model_expansions/quantum_operations/bind.py +64 -0
- classiq/model_expansions/quantum_operations/classicalif.py +39 -0
- classiq/model_expansions/quantum_operations/control.py +235 -0
- classiq/model_expansions/quantum_operations/emitter.py +215 -0
- classiq/model_expansions/quantum_operations/expression_operation.py +218 -0
- classiq/model_expansions/quantum_operations/inplace_binary_operation.py +250 -0
- classiq/model_expansions/quantum_operations/invert.py +38 -0
- classiq/model_expansions/quantum_operations/power.py +74 -0
- classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +174 -0
- classiq/model_expansions/quantum_operations/quantum_function_call.py +15 -0
- classiq/model_expansions/quantum_operations/repeat.py +33 -0
- classiq/model_expansions/quantum_operations/variable_decleration.py +28 -0
- classiq/model_expansions/quantum_operations/within_apply.py +46 -0
- classiq/model_expansions/scope.py +226 -0
- classiq/model_expansions/scope_initialization.py +136 -0
- classiq/model_expansions/sympy_conversion/__init__.py +0 -0
- classiq/model_expansions/sympy_conversion/arithmetics.py +49 -0
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +150 -0
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +113 -0
- classiq/model_expansions/utils/__init__.py +0 -0
- classiq/model_expansions/utils/counted_name_allocator.py +11 -0
- classiq/model_expansions/visitors/__init__.py +0 -0
- classiq/model_expansions/visitors/boolean_expression_transformers.py +214 -0
- classiq/model_expansions/visitors/variable_references.py +115 -0
- classiq/qmod/__init__.py +1 -3
- classiq/qmod/builtins/enums.py +33 -2
- classiq/qmod/builtins/functions/__init__.py +251 -0
- classiq/qmod/builtins/functions/amplitude_estimation.py +26 -0
- classiq/qmod/builtins/functions/arithmetic.py +68 -0
- classiq/qmod/builtins/functions/benchmarking.py +8 -0
- classiq/qmod/builtins/functions/chemistry.py +91 -0
- classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +105 -0
- classiq/qmod/builtins/functions/exponentiation.py +110 -0
- classiq/qmod/builtins/functions/finance.py +34 -0
- classiq/qmod/builtins/functions/grover.py +179 -0
- classiq/qmod/builtins/functions/hea.py +59 -0
- classiq/qmod/builtins/functions/linear_pauli_rotation.py +65 -0
- classiq/qmod/builtins/functions/modular_exponentiation.py +137 -0
- classiq/qmod/builtins/functions/operators.py +22 -0
- classiq/qmod/builtins/functions/qaoa_penalty.py +116 -0
- classiq/qmod/builtins/functions/qft.py +23 -0
- classiq/qmod/builtins/functions/qpe.py +39 -0
- classiq/qmod/builtins/functions/qsvm.py +24 -0
- classiq/qmod/builtins/functions/qsvt.py +136 -0
- classiq/qmod/builtins/functions/standard_gates.py +739 -0
- classiq/qmod/builtins/functions/state_preparation.py +356 -0
- classiq/qmod/builtins/functions/swap_test.py +25 -0
- classiq/qmod/builtins/structs.py +50 -28
- classiq/qmod/cparam.py +64 -0
- classiq/qmod/create_model_function.py +190 -0
- classiq/qmod/declaration_inferrer.py +52 -81
- classiq/qmod/expression_query.py +16 -0
- classiq/qmod/generative.py +48 -0
- classiq/qmod/model_state_container.py +1 -2
- classiq/qmod/native/pretty_printer.py +7 -11
- classiq/qmod/pretty_print/pretty_printer.py +7 -11
- classiq/qmod/python_classical_type.py +67 -0
- classiq/qmod/qfunc.py +19 -4
- classiq/qmod/qmod_parameter.py +15 -64
- classiq/qmod/qmod_variable.py +27 -45
- classiq/qmod/quantum_callable.py +1 -1
- classiq/qmod/quantum_expandable.py +10 -4
- classiq/qmod/quantum_function.py +22 -40
- classiq/qmod/semantics/error_manager.py +22 -10
- classiq/qmod/semantics/static_semantics_visitor.py +10 -12
- classiq/qmod/semantics/validation/types_validation.py +6 -7
- classiq/qmod/utilities.py +2 -2
- classiq/qmod/write_qmod.py +14 -0
- classiq/show.py +10 -0
- classiq/synthesis.py +46 -2
- {classiq-0.45.1.dist-info → classiq-0.46.0.dist-info}/METADATA +1 -1
- {classiq-0.45.1.dist-info → classiq-0.46.0.dist-info}/RECORD +138 -74
- classiq/interface/generator/functions/builtins/core_library/__init__.py +0 -16
- classiq/interface/generator/functions/builtins/core_library/atomic_quantum_functions.py +0 -710
- classiq/interface/generator/functions/builtins/core_library/exponentiation_functions.py +0 -105
- classiq/interface/generator/functions/builtins/open_lib_functions.py +0 -2489
- classiq/interface/generator/functions/builtins/quantum_operators.py +0 -24
- classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -1
- classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +0 -21
- classiq/qmod/builtins/functions.py +0 -1029
- {classiq-0.45.1.dist-info → classiq-0.46.0.dist-info}/WHEEL +0 -0
@@ -32,6 +32,12 @@ class ProviderTypeVendor:
|
|
32
32
|
|
33
33
|
|
34
34
|
class ClassiqSimulatorBackendNames(StrEnum):
|
35
|
+
"""
|
36
|
+
|
37
|
+
The simulator backends available in the Classiq provider.
|
38
|
+
|
39
|
+
"""
|
40
|
+
|
35
41
|
SIMULATOR = "simulator"
|
36
42
|
SIMULATOR_STATEVECTOR = "simulator_statevector"
|
37
43
|
SIMULATOR_DENSITY_MATRIX = "simulator_density_matrix"
|
@@ -39,6 +45,10 @@ class ClassiqSimulatorBackendNames(StrEnum):
|
|
39
45
|
|
40
46
|
|
41
47
|
class IonqBackendNames(StrEnum):
|
48
|
+
"""
|
49
|
+
IonQ backend names which Classiq Supports running on.
|
50
|
+
"""
|
51
|
+
|
42
52
|
SIMULATOR = "simulator"
|
43
53
|
HARMONY = "qpu.harmony"
|
44
54
|
ARIA_1 = "qpu.aria-1"
|
@@ -47,6 +57,10 @@ class IonqBackendNames(StrEnum):
|
|
47
57
|
|
48
58
|
|
49
59
|
class AzureQuantumBackendNames(StrEnum):
|
60
|
+
"""
|
61
|
+
AzureQuantum backend names which Classiq Supports running on.
|
62
|
+
"""
|
63
|
+
|
50
64
|
IONQ_ARIA_1 = "ionq.qpu.aria-1"
|
51
65
|
IONQ_ARIA_2 = "ionq.qpu.aria-2"
|
52
66
|
IONQ_QPU = "ionq.qpu"
|
@@ -73,6 +87,10 @@ class AzureQuantumBackendNames(StrEnum):
|
|
73
87
|
|
74
88
|
|
75
89
|
class AmazonBraketBackendNames(StrEnum):
|
90
|
+
"""
|
91
|
+
Amazon Braket backend names which Classiq Supports running on.
|
92
|
+
"""
|
93
|
+
|
76
94
|
AMAZON_BRAKET_SV1 = "SV1"
|
77
95
|
AMAZON_BRAKET_TN1 = "TN1"
|
78
96
|
AMAZON_BRAKET_DM1 = "dm1"
|
@@ -89,6 +107,10 @@ class AmazonBraketBackendNames(StrEnum):
|
|
89
107
|
# # Using _normalize_backend_name from `ibm_hardware_graphs.py`
|
90
108
|
# the_devices = [_normalize_backend_name(str(backend)) for backend in backends_list]
|
91
109
|
class IBMQHardwareNames(StrEnum):
|
110
|
+
"""
|
111
|
+
IBM backend names which Classiq Supports running on.
|
112
|
+
"""
|
113
|
+
|
92
114
|
ALMADEN = "Almaden"
|
93
115
|
ARMONK = "Armonk"
|
94
116
|
ATHENS = "Athens"
|
@@ -139,6 +161,10 @@ class IBMQHardwareNames(StrEnum):
|
|
139
161
|
|
140
162
|
|
141
163
|
class ClassiqNvidiaBackendNames(StrEnum):
|
164
|
+
"""
|
165
|
+
Classiq's Nvidia simulator backend names.
|
166
|
+
"""
|
167
|
+
|
142
168
|
SIMULATOR = "nvidia_state_vector_simulator"
|
143
169
|
|
144
170
|
|
@@ -146,10 +172,18 @@ AllClassiqBackendNames = Union[ClassiqSimulatorBackendNames, ClassiqNvidiaBacken
|
|
146
172
|
|
147
173
|
|
148
174
|
class GoogleNvidiaBackendNames(StrEnum):
|
175
|
+
"""
|
176
|
+
Google backend names which Classiq Supports running on.
|
177
|
+
"""
|
178
|
+
|
149
179
|
CUQUANTUM = "cuquantum"
|
150
180
|
|
151
181
|
|
152
182
|
class AliceBobBackendNames(StrEnum):
|
183
|
+
"""
|
184
|
+
Alice & Bob backend names which Classiq Supports running on.
|
185
|
+
"""
|
186
|
+
|
153
187
|
PERFECT_QUBITS = "PERFECT_QUBITS"
|
154
188
|
LOGICAL_TARGET = "LOGICAL_TARGET"
|
155
189
|
LOGICAL_EARLY = "LOGICAL_EARLY"
|
@@ -157,6 +191,10 @@ class AliceBobBackendNames(StrEnum):
|
|
157
191
|
|
158
192
|
|
159
193
|
class OQCBackendNames(StrEnum):
|
194
|
+
"""
|
195
|
+
OQC backend names which Classiq Supports running on.
|
196
|
+
"""
|
197
|
+
|
160
198
|
LUCY = "Lucy"
|
161
199
|
|
162
200
|
|
@@ -1,23 +1,38 @@
|
|
1
|
-
|
1
|
+
import json
|
2
|
+
from typing import Any, Dict, Optional, Union
|
2
3
|
from uuid import UUID
|
3
4
|
|
4
5
|
from pydantic import BaseModel, Field
|
5
6
|
|
7
|
+
from classiq.interface.generator.generated_circuit_data import (
|
8
|
+
FunctionDebugInfoInterface,
|
9
|
+
)
|
6
10
|
from classiq.interface.ide.visual_model import OperationLevel
|
7
11
|
|
12
|
+
ParameterValue = Union[float, int, str, None]
|
13
|
+
|
8
14
|
|
9
15
|
class FunctionDebugInfo(BaseModel):
|
10
16
|
name: str
|
11
|
-
|
17
|
+
# ParameterValue appears in type only for backwards compatibility
|
18
|
+
parameters: Dict[str, str] = Field(type=Dict[str, ParameterValue])
|
12
19
|
level: OperationLevel
|
13
20
|
is_allocate_or_free: bool = Field(default=False)
|
14
21
|
|
22
|
+
@staticmethod
|
23
|
+
def param_controller(value: Any) -> str:
|
24
|
+
try:
|
25
|
+
return json.dumps(value)
|
26
|
+
except TypeError:
|
27
|
+
return repr(value)
|
28
|
+
|
15
29
|
|
16
30
|
class DebugInfoCollection(BaseModel):
|
17
31
|
# Pydantic only started supporting UUID as keys in Pydantic V2
|
18
32
|
# See https://github.com/pydantic/pydantic/issues/2096#issuecomment-814860206
|
19
33
|
# For now, we use strings as keys in the raw data and use UUID in the wrapper logic
|
20
34
|
data: Dict[str, FunctionDebugInfo] = Field(default_factory=dict)
|
35
|
+
blackbox_data: Dict[str, FunctionDebugInfoInterface] = Field(default_factory=dict)
|
21
36
|
|
22
37
|
def __setitem__(self, key: UUID, value: FunctionDebugInfo) -> None:
|
23
38
|
self.data[str(key)] = value
|
@@ -30,3 +45,8 @@ class DebugInfoCollection(BaseModel):
|
|
30
45
|
|
31
46
|
def __contains__(self, key: UUID) -> bool:
|
32
47
|
return str(key) in self.data
|
48
|
+
|
49
|
+
def get_blackbox_data(self, key: UUID) -> Optional[FunctionDebugInfoInterface]:
|
50
|
+
if (debug_info := self.get(key)) is None:
|
51
|
+
return None
|
52
|
+
return self.blackbox_data.get(debug_info.name)
|
classiq/interface/exceptions.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import logging
|
2
|
-
from typing import Iterable, List
|
2
|
+
from typing import Iterable, List, Optional
|
3
3
|
|
4
4
|
_logger = logging.getLogger(__name__)
|
5
5
|
|
@@ -180,3 +180,18 @@ class ClassiqSemanticError(ClassiqError):
|
|
180
180
|
|
181
181
|
class ClassiqDeprecationWarning(FutureWarning):
|
182
182
|
pass
|
183
|
+
|
184
|
+
|
185
|
+
class ClassiqExpansionError(ClassiqError):
|
186
|
+
pass
|
187
|
+
|
188
|
+
|
189
|
+
class ClassiqInternalError(ClassiqError):
|
190
|
+
def __init__(self, message: Optional[str] = None) -> None:
|
191
|
+
super().__init__(
|
192
|
+
"Internal error" if message is None else f"Internal error: {message}"
|
193
|
+
)
|
194
|
+
|
195
|
+
|
196
|
+
class ClassiqInternalExpansionError(ClassiqInternalError):
|
197
|
+
pass
|
@@ -24,6 +24,24 @@ class QaeWithQpeEstimationMethod(int, ReprEnum):
|
|
24
24
|
|
25
25
|
|
26
26
|
class ExecutionPreferences(pydantic.BaseModel):
|
27
|
+
"""
|
28
|
+
Represents the execution settings for running a quantum program.
|
29
|
+
Execution preferences for running a quantum program.
|
30
|
+
|
31
|
+
For more details, refer to:
|
32
|
+
`ExecutionPreferences example: [ExecutionPreferences](https://docs.classiq.io/latest/reference-manual/executor/?h=execution+pref#execution-preferences)..
|
33
|
+
|
34
|
+
Attributes:
|
35
|
+
noise_properties (Optional[NoiseProperties]): Properties defining the noise in the quantum circuit. Defaults to `None`.
|
36
|
+
random_seed (int): The random seed used for the execution. Defaults to a randomly generated seed.
|
37
|
+
backend_preferences (BackendPreferencesTypes): Preferences for the backend used to execute the circuit.
|
38
|
+
Defaults to the Classiq Simulator.
|
39
|
+
num_shots (Optional[pydantic.PositiveInt]): The number of shots (executions) to be performed.
|
40
|
+
transpile_to_hardware (TranspilationOption): Option to transpile the circuit to the hardware's basis gates
|
41
|
+
before execution. Defaults to `TranspilationOption.DECOMPOSE`.
|
42
|
+
job_name (Optional[str]): The name of the job, with a minimum length of 1 character.
|
43
|
+
"""
|
44
|
+
|
27
45
|
noise_properties: Optional[NoiseProperties] = pydantic.Field(
|
28
46
|
default=None, description="Properties of the noise in the circuit"
|
29
47
|
)
|
@@ -1,41 +1,20 @@
|
|
1
|
-
import functools
|
2
1
|
from enum import Enum
|
3
2
|
|
4
|
-
from classiq.interface.generator.expressions.expression import Expression
|
5
3
|
from classiq.interface.generator.functions.classical_function_declaration import (
|
6
4
|
ClassicalFunctionDeclaration,
|
7
5
|
)
|
8
6
|
from classiq.interface.generator.functions.classical_type import (
|
9
|
-
Bool,
|
10
7
|
ClassicalList,
|
11
|
-
Integer,
|
12
|
-
Real,
|
13
8
|
VQEResult,
|
14
9
|
)
|
15
|
-
from classiq.interface.generator.functions.
|
16
|
-
PortDeclarationDirection,
|
17
|
-
)
|
18
|
-
from classiq.interface.generator.functions.type_name import Struct, TypeName
|
19
|
-
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
10
|
+
from classiq.interface.generator.functions.type_name import Struct
|
20
11
|
from classiq.interface.model.classical_parameter_declaration import (
|
21
12
|
ClassicalParameterDeclaration,
|
22
13
|
)
|
23
|
-
from classiq.interface.model.port_declaration import PortDeclaration
|
24
|
-
from classiq.interface.model.quantum_function_declaration import (
|
25
|
-
NamedParamsQuantumFunctionDeclaration,
|
26
|
-
)
|
27
14
|
|
28
15
|
MOLECULE_PROBLEM_PARAM = ClassicalParameterDeclaration(
|
29
16
|
name="molecule_problem", classical_type=Struct(name="MoleculeProblem")
|
30
17
|
)
|
31
|
-
MOLECULE_PROBLEM_SIZE = "get_field(get_field(molecule_problem_to_hamiltonian(molecule_problem)[0], 'pauli'), 'len')"
|
32
|
-
MOLECULE_PROBLEM_PORT = PortDeclaration(
|
33
|
-
name="qbv",
|
34
|
-
direction=PortDeclarationDirection.Inout,
|
35
|
-
size=Expression(
|
36
|
-
expr=MOLECULE_PROBLEM_SIZE,
|
37
|
-
),
|
38
|
-
)
|
39
18
|
|
40
19
|
FOCK_HAMILTONIAN_PROBLEM_PARAM = ClassicalParameterDeclaration(
|
41
20
|
name="fock_hamiltonian_problem",
|
@@ -43,153 +22,12 @@ FOCK_HAMILTONIAN_PROBLEM_PARAM = ClassicalParameterDeclaration(
|
|
43
22
|
)
|
44
23
|
FOCK_HAMILTONIAN_SIZE = "get_field(get_field(fock_hamiltonian_problem_to_hamiltonian(fock_hamiltonian_problem)[0], 'pauli'), 'len')"
|
45
24
|
|
46
|
-
FOCK_HAMILTONIAN_PROBLEM_PORT = PortDeclaration(
|
47
|
-
name="qbv",
|
48
|
-
direction=PortDeclarationDirection.Inout,
|
49
|
-
size=Expression(expr=FOCK_HAMILTONIAN_SIZE),
|
50
|
-
)
|
51
|
-
|
52
25
|
|
53
26
|
class ChemistryProblemType(Enum):
|
54
27
|
MoleculeProblem = "molecule_problem"
|
55
28
|
FockHamiltonianProblem = "fock_hamiltonian_problem"
|
56
29
|
|
57
30
|
|
58
|
-
MOLECULE_UCC_ANSATZ = NamedParamsQuantumFunctionDeclaration(
|
59
|
-
name="molecule_ucc",
|
60
|
-
positional_arg_declarations=[
|
61
|
-
MOLECULE_PROBLEM_PARAM,
|
62
|
-
ClassicalParameterDeclaration(
|
63
|
-
name="excitations", classical_type=ClassicalList(element_type=Integer())
|
64
|
-
),
|
65
|
-
MOLECULE_PROBLEM_PORT,
|
66
|
-
],
|
67
|
-
)
|
68
|
-
|
69
|
-
|
70
|
-
MOLECULE_HVA_ANSATZ = NamedParamsQuantumFunctionDeclaration(
|
71
|
-
name="molecule_hva",
|
72
|
-
positional_arg_declarations=[
|
73
|
-
MOLECULE_PROBLEM_PARAM,
|
74
|
-
ClassicalParameterDeclaration(name="reps", classical_type=Integer()),
|
75
|
-
MOLECULE_PROBLEM_PORT,
|
76
|
-
],
|
77
|
-
)
|
78
|
-
|
79
|
-
|
80
|
-
MOLECULE_HARTREE_FOCK = NamedParamsQuantumFunctionDeclaration(
|
81
|
-
name="molecule_hartree_fock",
|
82
|
-
positional_arg_declarations=[
|
83
|
-
MOLECULE_PROBLEM_PARAM,
|
84
|
-
MOLECULE_PROBLEM_PORT,
|
85
|
-
],
|
86
|
-
)
|
87
|
-
|
88
|
-
|
89
|
-
FOCK_HAMILTONIAN_UCC_ANSATZ = NamedParamsQuantumFunctionDeclaration(
|
90
|
-
name="fock_hamiltonian_ucc",
|
91
|
-
positional_arg_declarations=[
|
92
|
-
FOCK_HAMILTONIAN_PROBLEM_PARAM,
|
93
|
-
ClassicalParameterDeclaration(
|
94
|
-
name="excitations", classical_type=ClassicalList(element_type=Integer())
|
95
|
-
),
|
96
|
-
FOCK_HAMILTONIAN_PROBLEM_PORT,
|
97
|
-
],
|
98
|
-
)
|
99
|
-
|
100
|
-
FOCK_HAMILTONIAN_HVA_ANSATZ = NamedParamsQuantumFunctionDeclaration(
|
101
|
-
name="fock_hamiltonian_hva",
|
102
|
-
positional_arg_declarations=[
|
103
|
-
FOCK_HAMILTONIAN_PROBLEM_PARAM,
|
104
|
-
ClassicalParameterDeclaration(name="reps", classical_type=Integer()),
|
105
|
-
FOCK_HAMILTONIAN_PROBLEM_PORT,
|
106
|
-
],
|
107
|
-
)
|
108
|
-
|
109
|
-
FOCK_HAMILTONIAN_HARTREE_FOCK = NamedParamsQuantumFunctionDeclaration(
|
110
|
-
name="fock_hamiltonian_hartree_fock",
|
111
|
-
positional_arg_declarations=[
|
112
|
-
FOCK_HAMILTONIAN_PROBLEM_PARAM,
|
113
|
-
FOCK_HAMILTONIAN_PROBLEM_PORT,
|
114
|
-
],
|
115
|
-
)
|
116
|
-
|
117
|
-
|
118
|
-
MOLECULE_PROBLEM = StructDeclaration(
|
119
|
-
name="MoleculeProblem",
|
120
|
-
variables={
|
121
|
-
"mapping": Integer(),
|
122
|
-
"z2_symmetries": Bool(),
|
123
|
-
# A negative number of qubits is considered None
|
124
|
-
# basis: str = pydantic.Field(default="sto3g", description="Molecular basis set")
|
125
|
-
"molecule": Struct(name="Molecule"),
|
126
|
-
"freeze_core": Bool(),
|
127
|
-
"remove_orbitals": ClassicalList(element_type=Integer()),
|
128
|
-
},
|
129
|
-
)
|
130
|
-
|
131
|
-
MOLECULE = StructDeclaration(
|
132
|
-
name="Molecule",
|
133
|
-
variables={
|
134
|
-
"atoms": ClassicalList(element_type=Struct(name="ChemistryAtom")),
|
135
|
-
"spin": Integer(),
|
136
|
-
"charge": Integer(),
|
137
|
-
},
|
138
|
-
)
|
139
|
-
|
140
|
-
CHEMISTRY_ATOM = StructDeclaration(
|
141
|
-
name="ChemistryAtom",
|
142
|
-
variables={
|
143
|
-
"element": Integer(),
|
144
|
-
"position": Struct(name="Position"),
|
145
|
-
},
|
146
|
-
)
|
147
|
-
|
148
|
-
POSITION = StructDeclaration(
|
149
|
-
name="Position", variables={"x": Real(), "y": Real(), "z": Real()}
|
150
|
-
)
|
151
|
-
|
152
|
-
FockHamiltonian = functools.partial(
|
153
|
-
ClassicalList, element_type=Struct(name="LadderTerm")
|
154
|
-
)
|
155
|
-
|
156
|
-
FOCK_HAMILTONIAN_PROBLEM = StructDeclaration(
|
157
|
-
name="FockHamiltonianProblem",
|
158
|
-
variables={
|
159
|
-
"mapping": Integer(),
|
160
|
-
"z2_symmetries": Bool(),
|
161
|
-
"terms": FockHamiltonian(),
|
162
|
-
"num_particles": ClassicalList(element_type=Integer()),
|
163
|
-
},
|
164
|
-
)
|
165
|
-
|
166
|
-
LADDER_TERM = StructDeclaration(
|
167
|
-
name="LadderTerm",
|
168
|
-
variables={
|
169
|
-
"coefficient": Real(),
|
170
|
-
"ops": ClassicalList(element_type=Struct(name="LadderOp")),
|
171
|
-
},
|
172
|
-
)
|
173
|
-
|
174
|
-
LADDER_OP = StructDeclaration(
|
175
|
-
name="LadderOp",
|
176
|
-
variables={
|
177
|
-
"op": TypeName(name="LadderOperator"),
|
178
|
-
"index": Integer(),
|
179
|
-
},
|
180
|
-
)
|
181
|
-
|
182
|
-
MOLECULE_RESULT = StructDeclaration(
|
183
|
-
name="MoleculeResult",
|
184
|
-
variables={
|
185
|
-
"energy": Real(),
|
186
|
-
"nuclear_repulsion_energy": Real(),
|
187
|
-
"total_energy": Real(),
|
188
|
-
"hartree_fock_energy": Real(),
|
189
|
-
"vqe_result": VQEResult(),
|
190
|
-
},
|
191
|
-
)
|
192
|
-
|
193
31
|
MOLECULE_PROBLEM_TO_HAMILTONIAN = ClassicalFunctionDeclaration(
|
194
32
|
name="molecule_problem_to_hamiltonian",
|
195
33
|
positional_parameters=[
|
@@ -223,21 +61,7 @@ MOLECULE_GROUND_STATE_SOLUTION_POST_PROCESS = ClassicalFunctionDeclaration(
|
|
223
61
|
)
|
224
62
|
|
225
63
|
__all__ = [
|
226
|
-
"MOLECULE_UCC_ANSATZ",
|
227
|
-
"MOLECULE_HVA_ANSATZ",
|
228
|
-
"MOLECULE_HARTREE_FOCK",
|
229
|
-
"FOCK_HAMILTONIAN_UCC_ANSATZ",
|
230
|
-
"FOCK_HAMILTONIAN_HVA_ANSATZ",
|
231
|
-
"FOCK_HAMILTONIAN_HARTREE_FOCK",
|
232
|
-
"MOLECULE_PROBLEM",
|
233
|
-
"MOLECULE",
|
234
|
-
"CHEMISTRY_ATOM",
|
235
|
-
"POSITION",
|
236
|
-
"FOCK_HAMILTONIAN_PROBLEM",
|
237
|
-
"LADDER_TERM",
|
238
|
-
"LADDER_OP",
|
239
64
|
"MOLECULE_PROBLEM_TO_HAMILTONIAN",
|
240
65
|
"FOCK_HAMILTONIAN_PROBLEM_TO_HAMILTONIAN",
|
241
66
|
"MOLECULE_GROUND_STATE_SOLUTION_POST_PROCESS",
|
242
|
-
"MOLECULE_RESULT",
|
243
67
|
]
|
@@ -3,27 +3,15 @@ from classiq.interface.generator.functions.classical_function_declaration import
|
|
3
3
|
)
|
4
4
|
from classiq.interface.generator.functions.classical_type import (
|
5
5
|
ClassicalList,
|
6
|
-
Integer,
|
7
6
|
Real,
|
8
7
|
StructMetaType,
|
9
8
|
VQEResult,
|
10
9
|
)
|
11
10
|
from classiq.interface.generator.functions.type_name import Struct
|
12
|
-
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
13
11
|
from classiq.interface.model.classical_parameter_declaration import (
|
14
12
|
ClassicalParameterDeclaration,
|
15
13
|
)
|
16
14
|
|
17
|
-
COMBINATORIAL_OPTIMIZATION_SOLUTION = StructDeclaration(
|
18
|
-
name="CombinatorialOptimizationSolution",
|
19
|
-
variables={
|
20
|
-
"probability": Real(),
|
21
|
-
"cost": Real(),
|
22
|
-
"solution": ClassicalList(element_type=Integer()),
|
23
|
-
"count": Integer(),
|
24
|
-
},
|
25
|
-
)
|
26
|
-
|
27
15
|
OPTIMIZATION_PROBLEM_TO_HAMILTONIAN = ClassicalFunctionDeclaration(
|
28
16
|
name="optimization_problem_to_hamiltonian",
|
29
17
|
positional_parameters=[
|
@@ -5,17 +5,11 @@ from classiq.interface.generator.expressions.expression import Expression
|
|
5
5
|
from classiq.interface.generator.functions.classical_function_declaration import (
|
6
6
|
ClassicalFunctionDeclaration,
|
7
7
|
)
|
8
|
-
from classiq.interface.generator.functions.classical_type import
|
9
|
-
Bool,
|
10
|
-
ClassicalList,
|
11
|
-
Integer,
|
12
|
-
Real,
|
13
|
-
)
|
8
|
+
from classiq.interface.generator.functions.classical_type import Real
|
14
9
|
from classiq.interface.generator.functions.port_declaration import (
|
15
10
|
PortDeclarationDirection,
|
16
11
|
)
|
17
12
|
from classiq.interface.generator.functions.type_name import Struct
|
18
|
-
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
19
13
|
from classiq.interface.model.classical_parameter_declaration import (
|
20
14
|
ClassicalParameterDeclaration,
|
21
15
|
)
|
@@ -23,6 +17,7 @@ from classiq.interface.model.port_declaration import PortDeclaration
|
|
23
17
|
from classiq.interface.model.quantum_function_declaration import (
|
24
18
|
NamedParamsQuantumFunctionDeclaration,
|
25
19
|
)
|
20
|
+
from classiq.interface.model.quantum_type import QuantumBit, QuantumBitvector
|
26
21
|
|
27
22
|
FUNCTION_PORT_NAME = "func_port"
|
28
23
|
OBJECTIVE_PORT_NAME = "obj_port"
|
@@ -54,13 +49,17 @@ def _generate_finance_function(
|
|
54
49
|
),
|
55
50
|
PortDeclaration(
|
56
51
|
name=FUNCTION_PORT_NAME,
|
52
|
+
quantum_type=QuantumBitvector(
|
53
|
+
length=Expression(
|
54
|
+
expr=FINANCE_FUNCTION_PORT_SIZE_MAPPING[finance_model]
|
55
|
+
)
|
56
|
+
),
|
57
57
|
direction=PortDeclarationDirection.Inout,
|
58
|
-
size=Expression(expr=FINANCE_FUNCTION_PORT_SIZE_MAPPING[finance_model]),
|
59
58
|
),
|
60
59
|
PortDeclaration(
|
61
60
|
name=OBJECTIVE_PORT_NAME,
|
61
|
+
quantum_type=QuantumBit(),
|
62
62
|
direction=PortDeclarationDirection.Inout,
|
63
|
-
size=Expression(expr="1"),
|
64
63
|
),
|
65
64
|
],
|
66
65
|
)
|
@@ -70,37 +69,6 @@ LOG_NORMAL_FINANCE_FUNCTION = _generate_finance_function(FinanceModelType.LogNor
|
|
70
69
|
|
71
70
|
GAUSSIAN_FINANCE_FUNCTION = _generate_finance_function(FinanceModelType.Gaussian)
|
72
71
|
|
73
|
-
GAUSSIAN_MODEL = StructDeclaration(
|
74
|
-
name="GaussianModel",
|
75
|
-
variables={
|
76
|
-
"num_qubits": Integer(),
|
77
|
-
"normal_max_value": Real(),
|
78
|
-
"default_probabilities": ClassicalList(element_type=Real()),
|
79
|
-
"rhos": ClassicalList(element_type=Real()),
|
80
|
-
"loss": ClassicalList(element_type=Integer()),
|
81
|
-
"min_loss": Integer(),
|
82
|
-
},
|
83
|
-
)
|
84
|
-
|
85
|
-
|
86
|
-
LOG_NORMAL_MODEL = StructDeclaration(
|
87
|
-
name="LogNormalModel",
|
88
|
-
variables={"num_qubits": Integer(), "mu": Real(), "sigma": Real()},
|
89
|
-
)
|
90
|
-
|
91
|
-
|
92
|
-
FINANCE_FUNCTION = StructDeclaration(
|
93
|
-
name="FinanceFunction",
|
94
|
-
variables={
|
95
|
-
"f": Integer(),
|
96
|
-
"threshold": Real(),
|
97
|
-
"larger": Bool(),
|
98
|
-
"polynomial_degree": Integer(),
|
99
|
-
"use_chebyshev_polynomial_approximation": Bool(),
|
100
|
-
"tail_probability": Real(),
|
101
|
-
},
|
102
|
-
)
|
103
|
-
|
104
72
|
LOG_NORMAL_FINANCE_POST_PROCESS = ClassicalFunctionDeclaration(
|
105
73
|
name="log_normal_finance_post_process",
|
106
74
|
positional_parameters=[
|
@@ -132,9 +100,6 @@ GAUSSIAN_FINANCE_POST_PROCESS = ClassicalFunctionDeclaration(
|
|
132
100
|
__all__ = [
|
133
101
|
"LOG_NORMAL_FINANCE_FUNCTION",
|
134
102
|
"GAUSSIAN_FINANCE_FUNCTION",
|
135
|
-
"GAUSSIAN_MODEL",
|
136
|
-
"LOG_NORMAL_MODEL",
|
137
|
-
"FINANCE_FUNCTION",
|
138
103
|
"LOG_NORMAL_FINANCE_POST_PROCESS",
|
139
104
|
"GAUSSIAN_FINANCE_POST_PROCESS",
|
140
105
|
]
|
@@ -1,84 +1,6 @@
|
|
1
1
|
import enum
|
2
2
|
|
3
|
-
from classiq.interface.generator.expressions.expression import Expression
|
4
|
-
from classiq.interface.generator.functions.classical_type import (
|
5
|
-
ClassicalList,
|
6
|
-
Integer,
|
7
|
-
Real,
|
8
|
-
)
|
9
|
-
from classiq.interface.generator.functions.port_declaration import (
|
10
|
-
PortDeclarationDirection,
|
11
|
-
)
|
12
|
-
from classiq.interface.generator.functions.type_name import Enum, Struct
|
13
|
-
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
14
|
-
from classiq.interface.model.classical_parameter_declaration import (
|
15
|
-
ClassicalParameterDeclaration,
|
16
|
-
)
|
17
|
-
from classiq.interface.model.port_declaration import PortDeclaration
|
18
|
-
from classiq.interface.model.quantum_function_declaration import (
|
19
|
-
NamedParamsQuantumFunctionDeclaration,
|
20
|
-
)
|
21
|
-
|
22
3
|
|
23
4
|
class FeatureMapType(enum.Enum):
|
24
5
|
BlochSphere = "bloch_sphere"
|
25
6
|
Pauli = "pauli"
|
26
|
-
|
27
|
-
|
28
|
-
QSVM_PAULI_FEATURE_MAP_SIZE = "get_field(feature_map, 'feature_dimension')"
|
29
|
-
QSVM_PAULI_FEATURE_MAP = NamedParamsQuantumFunctionDeclaration(
|
30
|
-
name="pauli_feature_map",
|
31
|
-
positional_arg_declarations=[
|
32
|
-
ClassicalParameterDeclaration(
|
33
|
-
name="feature_map", classical_type=Struct(name="QSVMFeatureMapPauli")
|
34
|
-
),
|
35
|
-
PortDeclaration(
|
36
|
-
name="qbv",
|
37
|
-
direction=PortDeclarationDirection.Inout,
|
38
|
-
size=Expression(expr=QSVM_PAULI_FEATURE_MAP_SIZE),
|
39
|
-
),
|
40
|
-
],
|
41
|
-
)
|
42
|
-
|
43
|
-
QSVM_BLOCH_SPHERE_FEATURE_MAP_SIZE = "ceiling(feature_dimension/2)"
|
44
|
-
QSVM_BLOCH_SPHERE_FEATURE_MAP = NamedParamsQuantumFunctionDeclaration(
|
45
|
-
name="bloch_sphere_feature_map",
|
46
|
-
positional_arg_declarations=[
|
47
|
-
ClassicalParameterDeclaration(
|
48
|
-
name="feature_dimension", classical_type=Integer()
|
49
|
-
),
|
50
|
-
PortDeclaration(
|
51
|
-
name="qbv",
|
52
|
-
direction=PortDeclarationDirection.Inout,
|
53
|
-
size=Expression(expr=QSVM_BLOCH_SPHERE_FEATURE_MAP_SIZE),
|
54
|
-
),
|
55
|
-
],
|
56
|
-
)
|
57
|
-
|
58
|
-
QSVM_FEATURE_MAP_PAULI = StructDeclaration(
|
59
|
-
name="QSVMFeatureMapPauli",
|
60
|
-
variables={
|
61
|
-
"feature_dimension": Integer(),
|
62
|
-
"reps": Integer(),
|
63
|
-
"entanglement": Integer(),
|
64
|
-
"alpha": Real(),
|
65
|
-
"paulis": ClassicalList(
|
66
|
-
element_type=ClassicalList(element_type=Enum(name="Pauli"))
|
67
|
-
),
|
68
|
-
},
|
69
|
-
)
|
70
|
-
|
71
|
-
QSVM_RESULT = StructDeclaration(
|
72
|
-
name="QsvmResult",
|
73
|
-
variables={
|
74
|
-
"test_score": Real(),
|
75
|
-
"predicted_labels": ClassicalList(element_type=Real()),
|
76
|
-
},
|
77
|
-
)
|
78
|
-
|
79
|
-
__all__ = [
|
80
|
-
"QSVM_RESULT",
|
81
|
-
"QSVM_PAULI_FEATURE_MAP",
|
82
|
-
"QSVM_BLOCH_SPHERE_FEATURE_MAP",
|
83
|
-
"QSVM_FEATURE_MAP_PAULI",
|
84
|
-
]
|
@@ -3,12 +3,9 @@ from typing import Any, Iterable
|
|
3
3
|
from classiq.interface.generator.functions.classical_function_declaration import (
|
4
4
|
ClassicalFunctionDeclaration,
|
5
5
|
)
|
6
|
-
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
7
6
|
|
8
7
|
|
9
8
|
def populate_builtin_declarations(decls: Iterable[Any]) -> None:
|
10
9
|
for decl in decls:
|
11
10
|
if isinstance(decl, ClassicalFunctionDeclaration):
|
12
11
|
ClassicalFunctionDeclaration.FOREIGN_FUNCTION_DECLARATIONS[decl.name] = decl
|
13
|
-
if isinstance(decl, StructDeclaration):
|
14
|
-
StructDeclaration.BUILTIN_STRUCT_DECLARATIONS[decl.name] = decl
|
@@ -1,15 +0,0 @@
|
|
1
|
-
from classiq.interface.generator.functions.builtins.core_library import CORE_LIB_DECLS
|
2
|
-
from classiq.interface.generator.functions.builtins.open_lib_functions import (
|
3
|
-
OPEN_LIB_DECLS,
|
4
|
-
)
|
5
|
-
from classiq.interface.generator.functions.builtins.quantum_operators import (
|
6
|
-
STD_QMOD_OPERATORS,
|
7
|
-
)
|
8
|
-
from classiq.interface.helpers.pydantic_model_helpers import nameables_to_dict
|
9
|
-
from classiq.interface.model.quantum_function_declaration import (
|
10
|
-
QuantumFunctionDeclaration,
|
11
|
-
)
|
12
|
-
|
13
|
-
QuantumFunctionDeclaration.BUILTIN_FUNCTION_DECLARATIONS.update(
|
14
|
-
nameables_to_dict(STD_QMOD_OPERATORS + CORE_LIB_DECLS + OPEN_LIB_DECLS)
|
15
|
-
)
|
@@ -8,6 +8,7 @@ from classiq.interface.generator.register_role import RegisterRole
|
|
8
8
|
from classiq.interface.generator.synthesis_metadata.synthesis_execution_data import (
|
9
9
|
ExecutionData,
|
10
10
|
)
|
11
|
+
from classiq.interface.ide.visual_model import OperationParameter
|
11
12
|
|
12
13
|
ParameterName = str
|
13
14
|
IOQubitMapping: TypeAlias = Dict[str, Tuple[int, ...]]
|
@@ -100,6 +101,7 @@ class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
100
101
|
relative_qubits: Tuple[int, ...]
|
101
102
|
absolute_qubits: Optional[Tuple[int, ...]]
|
102
103
|
is_basis_gate: Optional[bool]
|
104
|
+
parameters: List[OperationParameter] = list()
|
103
105
|
|
104
106
|
@property
|
105
107
|
def registers(self) -> List[GeneratedRegister]:
|