classiq 0.86.1__py3-none-any.whl → 0.88.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.
Potentially problematic release.
This version of classiq might be problematic. Click here for more details.
- classiq/__init__.py +2 -0
- classiq/applications/__init__.py +1 -2
- classiq/applications/chemistry/hartree_fock.py +5 -1
- classiq/applications/chemistry/op_utils.py +2 -2
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +1 -1
- classiq/applications/combinatorial_helpers/encoding_mapping.py +11 -15
- classiq/applications/combinatorial_helpers/encoding_utils.py +6 -6
- classiq/applications/combinatorial_helpers/memory.py +4 -4
- classiq/applications/combinatorial_helpers/optimization_model.py +5 -5
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +6 -10
- classiq/applications/combinatorial_helpers/pyomo_utils.py +27 -26
- classiq/applications/combinatorial_helpers/sympy_utils.py +2 -2
- classiq/applications/combinatorial_helpers/transformations/encoding.py +4 -6
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +4 -4
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +2 -2
- classiq/applications/combinatorial_helpers/transformations/penalty_support.py +3 -3
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +4 -0
- classiq/applications/hamiltonian/pauli_decomposition.py +34 -2
- classiq/evaluators/argument_types.py +15 -6
- classiq/evaluators/parameter_types.py +43 -39
- classiq/evaluators/qmod_annotated_expression.py +117 -17
- classiq/evaluators/qmod_expression_visitors/out_of_place_node_transformer.py +19 -0
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -5
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +66 -16
- classiq/evaluators/qmod_expression_visitors/qmod_expression_renamer.py +48 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +65 -72
- classiq/evaluators/qmod_node_evaluators/attribute_evaluation.py +13 -6
- classiq/evaluators/qmod_node_evaluators/binary_op_evaluation.py +175 -28
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +36 -19
- classiq/evaluators/qmod_node_evaluators/compare_evaluation.py +17 -5
- classiq/evaluators/qmod_node_evaluators/constant_evaluation.py +24 -2
- classiq/evaluators/qmod_node_evaluators/min_max_evaluation.py +97 -0
- classiq/evaluators/qmod_node_evaluators/name_evaluation.py +11 -26
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +56 -0
- classiq/evaluators/qmod_node_evaluators/piecewise_evaluation.py +40 -0
- classiq/evaluators/qmod_node_evaluators/struct_instantiation_evaluation.py +3 -4
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +51 -24
- classiq/evaluators/qmod_node_evaluators/unary_op_evaluation.py +53 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +28 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +188 -0
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +330 -0
- classiq/evaluators/quantum_type_utils.py +0 -131
- classiq/evaluators/type_type_match.py +1 -1
- classiq/execution/execution_session.py +18 -3
- classiq/execution/qnn.py +4 -1
- classiq/execution/user_budgets.py +1 -1
- classiq/interface/_version.py +1 -1
- classiq/interface/backend/backend_preferences.py +10 -30
- classiq/interface/backend/quantum_backend_providers.py +63 -52
- classiq/interface/execution/primitives.py +1 -0
- classiq/interface/generator/application_apis/__init__.py +0 -1
- classiq/interface/generator/arith/binary_ops.py +107 -115
- classiq/interface/generator/arith/extremum_operations.py +33 -45
- classiq/interface/generator/arith/number_utils.py +4 -1
- classiq/interface/generator/circuit_code/types_and_constants.py +0 -9
- classiq/interface/generator/compiler_keywords.py +2 -0
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -2
- classiq/interface/generator/function_param_list.py +129 -5
- classiq/interface/generator/functions/classical_type.py +67 -2
- classiq/interface/generator/functions/qmod_python_interface.py +15 -0
- classiq/interface/generator/functions/type_name.py +12 -0
- classiq/interface/generator/model/preferences/preferences.py +1 -17
- classiq/interface/generator/quantum_program.py +1 -13
- classiq/interface/generator/transpiler_basis_gates.py +5 -1
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -8
- classiq/interface/helpers/model_normalizer.py +2 -2
- classiq/interface/helpers/text_utils.py +7 -2
- classiq/interface/interface_version.py +1 -1
- classiq/interface/model/classical_if.py +48 -0
- classiq/interface/model/classical_parameter_declaration.py +4 -0
- classiq/interface/model/handle_binding.py +28 -16
- classiq/interface/model/port_declaration.py +12 -0
- classiq/interface/model/quantum_function_declaration.py +12 -0
- classiq/interface/model/quantum_type.py +117 -2
- classiq/interface/pretty_print/expression_to_qmod.py +7 -8
- classiq/interface/pyomo_extension/__init__.py +0 -4
- classiq/interface/pyomo_extension/pyomo_sympy_bimap.py +2 -2
- classiq/model_expansions/arithmetic.py +43 -1
- classiq/model_expansions/arithmetic_compute_result_attrs.py +255 -0
- classiq/model_expansions/capturing/captured_vars.py +2 -5
- classiq/model_expansions/quantum_operations/allocate.py +23 -16
- classiq/model_expansions/quantum_operations/arithmetic/explicit_boolean_expressions.py +1 -3
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +52 -71
- classiq/model_expansions/quantum_operations/bind.py +15 -7
- classiq/model_expansions/quantum_operations/call_emitter.py +2 -10
- classiq/model_expansions/quantum_operations/classical_var_emitter.py +6 -0
- classiq/model_expansions/quantum_operations/handle_evaluator.py +2 -8
- classiq/open_library/functions/__init__.py +4 -0
- classiq/open_library/functions/lcu.py +117 -0
- classiq/open_library/functions/state_preparation.py +47 -5
- classiq/qmod/builtins/__init__.py +0 -3
- classiq/qmod/builtins/classical_functions.py +0 -28
- classiq/qmod/builtins/enums.py +26 -20
- classiq/qmod/builtins/functions/__init__.py +0 -5
- classiq/qmod/builtins/operations.py +142 -0
- classiq/qmod/builtins/structs.py +33 -29
- classiq/qmod/native/pretty_printer.py +1 -1
- classiq/qmod/pretty_print/expression_to_python.py +1 -6
- classiq/qmod/pretty_print/pretty_printer.py +4 -1
- classiq/qmod/qmod_variable.py +94 -2
- classiq/qmod/semantics/annotation/call_annotation.py +4 -2
- classiq/qmod/semantics/annotation/qstruct_annotator.py +20 -5
- {classiq-0.86.1.dist-info → classiq-0.88.0.dist-info}/METADATA +5 -5
- {classiq-0.86.1.dist-info → classiq-0.88.0.dist-info}/RECORD +106 -124
- classiq/applications/finance/__init__.py +0 -15
- classiq/interface/finance/finance_modelling_params.py +0 -11
- classiq/interface/finance/function_input.py +0 -102
- classiq/interface/finance/gaussian_model_input.py +0 -50
- classiq/interface/finance/log_normal_model_input.py +0 -40
- classiq/interface/finance/model_input.py +0 -22
- classiq/interface/generator/amplitude_estimation.py +0 -34
- classiq/interface/generator/application_apis/finance_declarations.py +0 -108
- classiq/interface/generator/expressions/enums/__init__.py +0 -0
- classiq/interface/generator/expressions/enums/finance_functions.py +0 -12
- classiq/interface/generator/finance.py +0 -107
- classiq/interface/generator/function_param_list_without_self_reference.py +0 -160
- classiq/interface/generator/grover_diffuser.py +0 -93
- classiq/interface/generator/grover_operator.py +0 -106
- classiq/interface/generator/oracles/__init__.py +0 -3
- classiq/interface/generator/oracles/arithmetic_oracle.py +0 -82
- classiq/interface/generator/oracles/custom_oracle.py +0 -65
- classiq/interface/generator/oracles/oracle_abc.py +0 -76
- classiq/interface/generator/oracles/oracle_function_param_list.py +0 -6
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +0 -165
- classiq/interface/generator/qpe.py +0 -169
- classiq/interface/grover/__init__.py +0 -0
- classiq/interface/grover/grover_modelling_params.py +0 -13
- classiq/model_expansions/transformers/var_splitter.py +0 -224
- classiq/qmod/builtins/functions/finance.py +0 -34
- /classiq/{interface/finance → evaluators/qmod_type_inference}/__init__.py +0 -0
- {classiq-0.86.1.dist-info → classiq-0.88.0.dist-info}/WHEEL +0 -0
|
@@ -3,15 +3,10 @@ from classiq.interface.exceptions import (
|
|
|
3
3
|
ClassiqInternalExpansionError,
|
|
4
4
|
)
|
|
5
5
|
from classiq.interface.generator.expressions.expression import Expression
|
|
6
|
-
from classiq.interface.generator.functions.concrete_types import ConcreteQuantumType
|
|
7
|
-
from classiq.interface.generator.functions.type_name import (
|
|
8
|
-
TypeName,
|
|
9
|
-
)
|
|
10
6
|
from classiq.interface.model.bind_operation import BindOperation
|
|
11
7
|
from classiq.interface.model.inplace_binary_operation import BinaryOperation
|
|
12
8
|
from classiq.interface.model.quantum_type import (
|
|
13
9
|
QuantumBit,
|
|
14
|
-
QuantumBitvector,
|
|
15
10
|
QuantumNumeric,
|
|
16
11
|
QuantumScalar,
|
|
17
12
|
QuantumType,
|
|
@@ -20,129 +15,6 @@ from classiq.interface.model.quantum_type import (
|
|
|
20
15
|
from classiq.model_expansions.scope import QuantumSymbol, Scope
|
|
21
16
|
|
|
22
17
|
|
|
23
|
-
def copy_type_information(
|
|
24
|
-
from_type: QuantumType,
|
|
25
|
-
to_type: QuantumType,
|
|
26
|
-
to_param_name: str,
|
|
27
|
-
) -> None:
|
|
28
|
-
if isinstance(to_type, QuantumBit):
|
|
29
|
-
set_size(to_type, from_type.size_in_bits, to_param_name)
|
|
30
|
-
elif isinstance(to_type, QuantumNumeric):
|
|
31
|
-
if to_type.size is None and isinstance(from_type, QuantumNumeric):
|
|
32
|
-
to_type.is_signed = Expression(expr=str(from_type.sign_value))
|
|
33
|
-
to_type.fraction_digits = Expression(
|
|
34
|
-
expr=str(from_type.fraction_digits_value)
|
|
35
|
-
)
|
|
36
|
-
set_size(to_type, from_type.size_in_bits, to_param_name)
|
|
37
|
-
set_bounds(from_type, to_type)
|
|
38
|
-
elif isinstance(to_type, QuantumBitvector):
|
|
39
|
-
if isinstance(from_type, QuantumBitvector) and type( # noqa: E721
|
|
40
|
-
from_type.element_type
|
|
41
|
-
) == type(to_type.element_type):
|
|
42
|
-
copy_type_information(
|
|
43
|
-
from_type.element_type, to_type.element_type, to_param_name
|
|
44
|
-
)
|
|
45
|
-
set_size(to_type, from_type.size_in_bits, to_param_name)
|
|
46
|
-
elif isinstance(to_type, TypeName):
|
|
47
|
-
if isinstance(from_type, TypeName) and from_type.name == to_type.name:
|
|
48
|
-
for field in from_type.fields:
|
|
49
|
-
copy_type_information(
|
|
50
|
-
from_type.fields[field], to_type.fields[field], to_param_name
|
|
51
|
-
)
|
|
52
|
-
set_size(to_type, from_type.size_in_bits, to_param_name)
|
|
53
|
-
else:
|
|
54
|
-
raise ClassiqInternalExpansionError
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def set_size(quantum_type: QuantumType, size: int, param_name: str) -> None:
|
|
58
|
-
if size <= 0:
|
|
59
|
-
raise ClassiqExpansionError(
|
|
60
|
-
f"Size for {param_name!r} was deduced to be non-positive: {size!r}"
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
if quantum_type.has_size_in_bits and quantum_type.size_in_bits != size:
|
|
64
|
-
raise ClassiqExpansionError(
|
|
65
|
-
f"Size mismatch for variable {param_name!r} between declared size {quantum_type.size_in_bits} and assigned size {size}"
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
if isinstance(quantum_type, QuantumNumeric):
|
|
69
|
-
quantum_type.size = Expression(expr=str(size))
|
|
70
|
-
if not quantum_type.has_sign or not quantum_type.has_fraction_digits:
|
|
71
|
-
quantum_type.is_signed = Expression(expr="False")
|
|
72
|
-
quantum_type.fraction_digits = Expression(expr="0")
|
|
73
|
-
elif isinstance(quantum_type, QuantumBitvector):
|
|
74
|
-
if quantum_type.has_length:
|
|
75
|
-
if size % quantum_type.length_value != 0:
|
|
76
|
-
raise ClassiqExpansionError(
|
|
77
|
-
f"Size mismatch for variable {param_name!r}. Cannot fit {size} "
|
|
78
|
-
f"qubits into an array of {quantum_type.length_value} elements."
|
|
79
|
-
)
|
|
80
|
-
set_size(
|
|
81
|
-
quantum_type.element_type,
|
|
82
|
-
size // quantum_type.length_value,
|
|
83
|
-
param_name,
|
|
84
|
-
)
|
|
85
|
-
set_length_by_size(quantum_type, size, param_name)
|
|
86
|
-
elif isinstance(quantum_type, TypeName):
|
|
87
|
-
fields_without_size = [
|
|
88
|
-
field_type
|
|
89
|
-
for field_type in quantum_type.fields.values()
|
|
90
|
-
if not field_type.has_size_in_bits
|
|
91
|
-
]
|
|
92
|
-
if len(fields_without_size) > 1:
|
|
93
|
-
raise ClassiqInternalExpansionError(
|
|
94
|
-
f"QuantumStruct should have at most one field without "
|
|
95
|
-
f"predetermined size. Found {fields_without_size}."
|
|
96
|
-
)
|
|
97
|
-
if len(fields_without_size) == 1:
|
|
98
|
-
predetermined_size_part = sum(
|
|
99
|
-
field_type.size_in_bits if field_type.has_size_in_bits else 0
|
|
100
|
-
for field_type in quantum_type.fields.values()
|
|
101
|
-
)
|
|
102
|
-
set_size(fields_without_size[0], size - predetermined_size_part, param_name)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def set_element_type(
|
|
106
|
-
quantum_array: QuantumBitvector, element_type: ConcreteQuantumType
|
|
107
|
-
) -> None:
|
|
108
|
-
quantum_array.element_type = element_type
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def set_length(quantum_array: QuantumBitvector, length: int) -> None:
|
|
112
|
-
quantum_array.length = Expression(expr=str(length))
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def set_length_by_size(
|
|
116
|
-
quantum_array: QuantumBitvector, size: int, param_name: str
|
|
117
|
-
) -> None:
|
|
118
|
-
if size <= 0:
|
|
119
|
-
raise ClassiqExpansionError(
|
|
120
|
-
f"Size for {param_name!r} was deduced to be non-positive: {size!r}"
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
if quantum_array.has_size_in_bits and quantum_array.size_in_bits != size:
|
|
124
|
-
raise ClassiqExpansionError(
|
|
125
|
-
f"Size mismatch for variable {param_name!r} between declared size "
|
|
126
|
-
f"{quantum_array.size_in_bits} ({quantum_array.length_value} elements of "
|
|
127
|
-
f"size {quantum_array.element_type.size_in_bits}) and assigned size {size}."
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
if not quantum_array.element_type.has_size_in_bits:
|
|
131
|
-
raise ClassiqExpansionError(
|
|
132
|
-
f"Could not infer element size for array {param_name!r}."
|
|
133
|
-
)
|
|
134
|
-
element_size = quantum_array.element_type.size_in_bits
|
|
135
|
-
|
|
136
|
-
if size % element_size != 0:
|
|
137
|
-
raise ClassiqExpansionError(
|
|
138
|
-
f"Size mismatch for variable {param_name!r}. Cannot fit elements of type "
|
|
139
|
-
f"{quantum_array.element_type.qmod_type_name} (size {element_size}) into "
|
|
140
|
-
f"{size} qubits."
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
quantum_array.length = Expression(expr=str(size // element_size))
|
|
144
|
-
|
|
145
|
-
|
|
146
18
|
def validate_bind_targets(bind: BindOperation, scope: Scope) -> None:
|
|
147
19
|
illegal_qnum_bind_targets = []
|
|
148
20
|
for out_handle in bind.out_handles:
|
|
@@ -152,9 +24,6 @@ def validate_bind_targets(bind: BindOperation, scope: Scope) -> None:
|
|
|
152
24
|
continue
|
|
153
25
|
if not out_var_type.has_size_in_bits:
|
|
154
26
|
illegal_qnum_bind_targets.append(str(out_var.handle))
|
|
155
|
-
elif not out_var_type.has_sign:
|
|
156
|
-
assert not out_var_type.has_fraction_digits
|
|
157
|
-
illegal_qnum_bind_targets.append(str(out_var.handle))
|
|
158
27
|
if len(illegal_qnum_bind_targets) > 0:
|
|
159
28
|
raise ClassiqExpansionError(
|
|
160
29
|
f"QNum bind targets {illegal_qnum_bind_targets!r} must be declared or initialized with size, sign, and fraction digits"
|
|
@@ -21,7 +21,7 @@ def check_signature_match(
|
|
|
21
21
|
) -> None:
|
|
22
22
|
if len(decl_params) != len(op_params):
|
|
23
23
|
raise ClassiqExpansionError(
|
|
24
|
-
f"{location_str} should have {len(decl_params)} parameters, "
|
|
24
|
+
f"{location_str.capitalize()} should have {len(decl_params)} parameters, "
|
|
25
25
|
f"not {len(op_params)}"
|
|
26
26
|
)
|
|
27
27
|
for idx, (decl_param, op_param) in enumerate(zip(decl_params, op_params)):
|
|
@@ -340,6 +340,7 @@ class ExecutionSession:
|
|
|
340
340
|
initial_params: ExecutionParams,
|
|
341
341
|
max_iteration: int,
|
|
342
342
|
quantile: float = 1.0,
|
|
343
|
+
tolerance: Optional[float] = None,
|
|
343
344
|
) -> list[tuple[float, ExecutionParams]]:
|
|
344
345
|
"""
|
|
345
346
|
Minimizes the given cost function using the quantum program.
|
|
@@ -355,6 +356,7 @@ class ExecutionSession:
|
|
|
355
356
|
- The value is either a float or a list of floats.
|
|
356
357
|
max_iteration: The maximum number of iterations for the minimization.
|
|
357
358
|
quantile: The quantile to use for cost estimation.
|
|
359
|
+
tolerance: The tolerance for the minimization.
|
|
358
360
|
Returns:
|
|
359
361
|
A list of tuples, each containing the estimated cost and the corresponding parameters for that iteration.
|
|
360
362
|
`cost` is a float, and `parameters` is a dictionary matching the execution parameter format.
|
|
@@ -365,6 +367,7 @@ class ExecutionSession:
|
|
|
365
367
|
initial_params=initial_params,
|
|
366
368
|
max_iteration=max_iteration,
|
|
367
369
|
quantile=quantile,
|
|
370
|
+
tolerance=tolerance,
|
|
368
371
|
_check_deprecation=False,
|
|
369
372
|
)
|
|
370
373
|
result = job.get_minimization_result(_http_client=self._async_client)
|
|
@@ -379,6 +382,7 @@ class ExecutionSession:
|
|
|
379
382
|
initial_params: ExecutionParams,
|
|
380
383
|
max_iteration: int,
|
|
381
384
|
quantile: float = 1.0,
|
|
385
|
+
tolerance: Optional[float] = None,
|
|
382
386
|
*,
|
|
383
387
|
_check_deprecation: bool = True,
|
|
384
388
|
) -> ExecutionJob:
|
|
@@ -400,6 +404,7 @@ class ExecutionSession:
|
|
|
400
404
|
- The value is either a float or a list of floats.
|
|
401
405
|
max_iteration: The maximum number of iterations for the minimization.
|
|
402
406
|
quantile: The quantile to use for cost estimation.
|
|
407
|
+
tolerance: The tolerance for the minimization.
|
|
403
408
|
|
|
404
409
|
Returns:
|
|
405
410
|
The execution job.
|
|
@@ -424,6 +429,7 @@ class ExecutionSession:
|
|
|
424
429
|
initial_params=_initial_params,
|
|
425
430
|
max_iteration=max_iteration,
|
|
426
431
|
quantile=quantile,
|
|
432
|
+
tolerance=tolerance,
|
|
427
433
|
)
|
|
428
434
|
else:
|
|
429
435
|
_cost_function = self._hamiltonian_to_pauli_operator(cost_function)
|
|
@@ -432,6 +438,7 @@ class ExecutionSession:
|
|
|
432
438
|
initial_params=_initial_params,
|
|
433
439
|
max_iteration=max_iteration,
|
|
434
440
|
quantile=quantile,
|
|
441
|
+
tolerance=tolerance,
|
|
435
442
|
)
|
|
436
443
|
|
|
437
444
|
execution_primitives_input = PrimitivesInput(minimize=minimize)
|
|
@@ -530,7 +537,7 @@ class ExecutionSession:
|
|
|
530
537
|
return PauliOperator(pauli_list=pauli_list)
|
|
531
538
|
pauli_list = []
|
|
532
539
|
for term in cast(list, hamiltonian.terms):
|
|
533
|
-
paulis = ["I"] *
|
|
540
|
+
paulis = ["I"] * hamiltonian.num_qubits
|
|
534
541
|
for indexed_pauli in term.paulis:
|
|
535
542
|
paulis[len(paulis) - indexed_pauli.index - 1] = indexed_pauli.pauli.name
|
|
536
543
|
pauli_list.append(("".join(paulis), term.coefficient))
|
|
@@ -545,10 +552,18 @@ class ExecutionSession:
|
|
|
545
552
|
name: create_qvar_from_quantum_type(reg.quantum_types, name)
|
|
546
553
|
for name, reg in circuit_output_types.items()
|
|
547
554
|
}
|
|
548
|
-
|
|
555
|
+
creator_parameters = inspect.signature(
|
|
556
|
+
qmod_expression_creator
|
|
557
|
+
).parameters.keys()
|
|
558
|
+
for name in creator_parameters:
|
|
549
559
|
if name not in symbolic_output:
|
|
550
560
|
raise ClassiqValueError(
|
|
551
|
-
f"
|
|
561
|
+
f"Expected cost function with parameters {tuple(symbolic_output.keys())} corresponding to the quantum program outputs, but found '{name}'. "
|
|
562
|
+
)
|
|
563
|
+
for name in symbolic_output:
|
|
564
|
+
if name not in creator_parameters:
|
|
565
|
+
raise ClassiqValueError(
|
|
566
|
+
f"Expected cost function with parameter '{name}' corresponding to the quantum program outputs. "
|
|
552
567
|
)
|
|
553
568
|
|
|
554
569
|
qmod_expression = qmod_expression_creator(**symbolic_output)
|
classiq/execution/qnn.py
CHANGED
|
@@ -15,6 +15,7 @@ from classiq.interface.executor.quantum_code import Arguments, MultipleArguments
|
|
|
15
15
|
|
|
16
16
|
from classiq import QuantumProgram
|
|
17
17
|
from classiq.applications.combinatorial_helpers.pauli_helpers.pauli_utils import (
|
|
18
|
+
pauli_operator_to_hamiltonian,
|
|
18
19
|
pauli_operator_to_sparse_hamiltonian,
|
|
19
20
|
)
|
|
20
21
|
from classiq.execution.execution_session import ExecutionSession
|
|
@@ -27,7 +28,9 @@ def _execute_qnn_estimate(
|
|
|
27
28
|
arguments: list[Arguments],
|
|
28
29
|
observable: PauliOperator,
|
|
29
30
|
) -> ResultsCollection:
|
|
30
|
-
hamiltonian = pauli_operator_to_sparse_hamiltonian(
|
|
31
|
+
hamiltonian = pauli_operator_to_sparse_hamiltonian(
|
|
32
|
+
pauli_operator_to_hamiltonian(observable.pauli_list)
|
|
33
|
+
)
|
|
31
34
|
return [
|
|
32
35
|
TaggedEstimationResult(
|
|
33
36
|
name=DEFAULT_RESULT_NAME,
|
|
@@ -8,7 +8,7 @@ from classiq._internals.async_utils import syncify_function
|
|
|
8
8
|
|
|
9
9
|
PROVIDER_MAPPER = {
|
|
10
10
|
ProviderVendor.IONQ: "IONQ",
|
|
11
|
-
ProviderVendor.IBM_QUANTUM: "
|
|
11
|
+
ProviderVendor.IBM_QUANTUM: "IBM_CLOUD",
|
|
12
12
|
ProviderVendor.AZURE_QUANTUM: "AZURE",
|
|
13
13
|
ProviderVendor.AMAZON_BRAKET: "AMAZON",
|
|
14
14
|
ProviderVendor.GOOGLE: "GOOGLE",
|
classiq/interface/_version.py
CHANGED
|
@@ -209,23 +209,6 @@ class AwsBackendPreferences(BackendPreferences):
|
|
|
209
209
|
)
|
|
210
210
|
|
|
211
211
|
|
|
212
|
-
class IBMBackendProvider(BaseModel):
|
|
213
|
-
"""
|
|
214
|
-
|
|
215
|
-
Represents the provider specs for identifying an IBM Quantum backend.
|
|
216
|
-
|
|
217
|
-
Attributes:
|
|
218
|
-
hub (str): hub parameter of IBM Quantum provider. Defaults to `"ibm-q"`.
|
|
219
|
-
group (str): group parameter of IBM Quantum provider. Defaults to `"open"`.
|
|
220
|
-
project (str): project parameter of IBM Quantum provider. Defaults to `"main"`.
|
|
221
|
-
|
|
222
|
-
"""
|
|
223
|
-
|
|
224
|
-
hub: str = "ibm-q"
|
|
225
|
-
group: str = "open"
|
|
226
|
-
project: str = "main"
|
|
227
|
-
|
|
228
|
-
|
|
229
212
|
class IBMBackendPreferences(BackendPreferences):
|
|
230
213
|
"""
|
|
231
214
|
Represents the backend preferences specific to IBM Quantum services.
|
|
@@ -234,30 +217,28 @@ class IBMBackendPreferences(BackendPreferences):
|
|
|
234
217
|
specific to IBM Quantum backends.
|
|
235
218
|
|
|
236
219
|
Attributes:
|
|
237
|
-
backend_service_provider (ProviderTypeVendor.
|
|
238
|
-
access_token (Optional[str]): The IBM
|
|
239
|
-
|
|
240
|
-
|
|
220
|
+
backend_service_provider (ProviderTypeVendor.IBM_CLOUD): Indicates the backend service provider as IBM Cloud.
|
|
221
|
+
access_token (Optional[str]): The IBM Cloud access token to be used with IBM Quantum hosted backends. Defaults to `None`.
|
|
222
|
+
channel (str): Channel to use for IBM cloud backends. Defaults to `"ibm_cloud"`.
|
|
223
|
+
instance_crn (str): The IBM Cloud instance CRN (Cloud Resource Name) for the IBM Quantum service.
|
|
241
224
|
run_through_classiq (bool): Run through Classiq's credentials. Defaults to `False`.
|
|
242
225
|
|
|
243
226
|
See examples in the [IBM Quantum Backend Documentation](https://docs.classiq.io/latest/reference-manual/executor/cloud-providers/ibm-backends/?h=).
|
|
244
227
|
"""
|
|
245
228
|
|
|
246
|
-
backend_service_provider: ProviderTypeVendor.
|
|
229
|
+
backend_service_provider: ProviderTypeVendor.IBM_CLOUD = pydantic.Field(
|
|
247
230
|
default=ProviderVendor.IBM_QUANTUM
|
|
248
231
|
)
|
|
249
232
|
access_token: Optional[str] = pydantic.Field(
|
|
250
233
|
default=None,
|
|
251
|
-
description="IBM
|
|
234
|
+
description="IBM Cloud access token to be used"
|
|
252
235
|
" with IBM Quantum hosted backends",
|
|
253
236
|
)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
description="Provider specs. for identifying a single IBM Quantum provider.",
|
|
237
|
+
channel: Optional[str] = pydantic.Field(
|
|
238
|
+
default=None, description="Channel to use for IBM cloud backends."
|
|
257
239
|
)
|
|
258
|
-
|
|
259
|
-
default=None,
|
|
260
|
-
description="QCTRL API key to access QCTRL optimization abilities",
|
|
240
|
+
instance_crn: Optional[str] = pydantic.Field(
|
|
241
|
+
default=None, description="IBM Cloud instance CRN."
|
|
261
242
|
)
|
|
262
243
|
run_through_classiq: bool = pydantic.Field(
|
|
263
244
|
default=False,
|
|
@@ -544,7 +525,6 @@ __all__ = [
|
|
|
544
525
|
"ClassiqSimulatorBackendNames",
|
|
545
526
|
"GCPBackendPreferences",
|
|
546
527
|
"IBMBackendPreferences",
|
|
547
|
-
"IBMBackendProvider",
|
|
548
528
|
"IQCCBackendPreferences",
|
|
549
529
|
"IntelBackendNames",
|
|
550
530
|
"IntelBackendPreferences",
|
|
@@ -26,7 +26,7 @@ class ProviderVendor(StrEnum):
|
|
|
26
26
|
|
|
27
27
|
class ProviderTypeVendor:
|
|
28
28
|
CLASSIQ = Literal[ProviderVendor.CLASSIQ]
|
|
29
|
-
|
|
29
|
+
IBM_CLOUD = Literal[ProviderVendor.IBM_QUANTUM]
|
|
30
30
|
AZURE_QUANTUM = Literal[ProviderVendor.AZURE_QUANTUM]
|
|
31
31
|
AMAZON_BRAKET = Literal[ProviderVendor.AMAZON_BRAKET]
|
|
32
32
|
IONQ = Literal[ProviderVendor.IONQ]
|
|
@@ -108,63 +108,74 @@ class AmazonBraketBackendNames(StrEnum):
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
# The IBM devices were taken from:
|
|
111
|
-
# from
|
|
112
|
-
# provider =
|
|
111
|
+
# from qiskit_ibm_runtime.fake_provider import FakeProviderForBackendV2
|
|
112
|
+
# provider = FakeProviderForBackendV2()
|
|
113
113
|
# backends_list = provider.backends()
|
|
114
|
-
#
|
|
115
|
-
# the_devices = [_normalize_backend_name(str(backend)) for backend in backends_list]
|
|
114
|
+
# the_devices = ["ibm_" + backend.name.split('_')[1] for backend in backends_list.backends()]
|
|
116
115
|
class IBMQHardwareNames(StrEnum):
|
|
117
116
|
"""
|
|
118
117
|
IBM backend names which Classiq Supports running on.
|
|
119
118
|
"""
|
|
120
119
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
120
|
+
IBM_ALGIERS = "ibm_algiers"
|
|
121
|
+
IBM_ALMADEN = "ibm_almaden"
|
|
122
|
+
IBM_ARMONK = "ibm_armonk"
|
|
123
|
+
IBM_ATHENS = "ibm_athens"
|
|
124
|
+
IBM_AUCKLAND = "ibm_auckland"
|
|
125
|
+
IBM_BELEM = "ibm_belem"
|
|
126
|
+
IBM_BOEBLINGEN = "ibm_boeblingen"
|
|
127
|
+
IBM_BOGOTA = "ibm_bogota"
|
|
128
|
+
IBM_BRISBANE = "ibm_brisbane"
|
|
129
|
+
IBM_BROOKLYN = "ibm_brooklyn"
|
|
130
|
+
IBM_BURLINGTON = "ibm_burlington"
|
|
131
|
+
IBM_CAIRO = "ibm_cairo"
|
|
132
|
+
IBM_CAMBRIDGE = "ibm_cambridge"
|
|
133
|
+
IBM_CASABLANCA = "ibm_casablanca"
|
|
134
|
+
IBM_CUSCO = "ibm_cusco"
|
|
135
|
+
IBM_ESSEX = "ibm_essex"
|
|
136
|
+
IBM_FEZ = "ibm_fez"
|
|
137
|
+
IBM_FRACTIONAL = "ibm_fractional"
|
|
138
|
+
IBM_GENEVA = "ibm_geneva"
|
|
139
|
+
IBM_GUADALUPE = "ibm_guadalupe"
|
|
140
|
+
IBM_HANOI = "ibm_hanoi"
|
|
141
|
+
IBM_JAKARTA = "ibm_jakarta"
|
|
142
|
+
IBM_JOHANNESBURG = "ibm_johannesburg"
|
|
143
|
+
IBM_KAWASAKI = "ibm_kawasaki"
|
|
144
|
+
IBM_KOLKATA = "ibm_kolkata"
|
|
145
|
+
IBM_KYIV = "ibm_kyiv"
|
|
146
|
+
IBM_KYOTO = "ibm_kyoto"
|
|
147
|
+
IBM_LAGOS = "ibm_lagos"
|
|
148
|
+
IBM_LIMA = "ibm_lima"
|
|
149
|
+
IBM_LONDON = "ibm_london"
|
|
150
|
+
IBM_MANHATTAN = "ibm_manhattan"
|
|
151
|
+
IBM_MANILA = "ibm_manila"
|
|
152
|
+
IBM_MELBOURNE = "ibm_melbourne"
|
|
153
|
+
IBM_MARRAKESH = "ibm_marrakesh"
|
|
154
|
+
IBM_MONTREAL = "ibm_montreal"
|
|
155
|
+
IBM_MUMBAI = "ibm_mumbai"
|
|
156
|
+
IBM_NAIROBI = "ibm_nairobi"
|
|
157
|
+
IBM_OSAKA = "ibm_osaka"
|
|
158
|
+
IBM_OSLO = "ibm_oslo"
|
|
159
|
+
IBM_OURENSE = "ibm_ourense"
|
|
160
|
+
IBM_PARIS = "ibm_paris"
|
|
161
|
+
IBM_PEEKSKILL = "ibm_peekskill"
|
|
162
|
+
IBM_PERTH = "ibm_perth"
|
|
163
|
+
IBM_PRAGUE = "ibm_prague"
|
|
164
|
+
IBM_POUGHKEEPSIE = "ibm_poughkeepsie"
|
|
165
|
+
IBM_QUEBEC = "ibm_quebec"
|
|
166
|
+
IBM_QUITO = "ibm_quito"
|
|
167
|
+
IBM_ROCHESTER = "ibm_rochester"
|
|
168
|
+
IBM_ROME = "ibm_rome"
|
|
169
|
+
IBM_SANTIAGO = "ibm_santiago"
|
|
170
|
+
IBM_SHERBROOKE = "ibm_sherbrooke"
|
|
171
|
+
IBM_SINGAPORE = "ibm_singapore"
|
|
172
|
+
IBM_SYDNEY = "ibm_sydney"
|
|
173
|
+
IBM_TORINO = "ibm_torino"
|
|
174
|
+
IBM_TORONTO = "ibm_toronto"
|
|
175
|
+
IBM_VALENCIA = "ibm_valencia"
|
|
176
|
+
IBM_VIGO = "ibm_vigo"
|
|
177
|
+
IBM_WASHINGTON = "ibm_washington"
|
|
178
|
+
IBM_YORKTOWN = "ibm_yorktown"
|
|
168
179
|
|
|
169
180
|
|
|
170
181
|
class ClassiqNvidiaBackendNames(StrEnum):
|
|
@@ -6,7 +6,6 @@ from .arithmetic_declarations import * # noqa: F403
|
|
|
6
6
|
from .chemistry_declarations import * # noqa: F403
|
|
7
7
|
from .combinatorial_optimization_declarations import * # noqa: F403
|
|
8
8
|
from .entangler_declarations import * # noqa: F403
|
|
9
|
-
from .finance_declarations import * # noqa: F403
|
|
10
9
|
from .qsvm_declarations import * # noqa: F403
|
|
11
10
|
|
|
12
11
|
populate_builtin_declarations(vars().values())
|