classiq 0.37.0__py3-none-any.whl → 0.38.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 +2 -2
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +1 -1
- classiq/_analyzer_extras/interactive_hardware.py +3 -3
- classiq/_internals/api_wrapper.py +24 -16
- classiq/_internals/async_utils.py +1 -74
- classiq/_internals/authentication/device.py +9 -4
- classiq/_internals/authentication/password_manager.py +25 -10
- classiq/_internals/authentication/token_manager.py +2 -2
- classiq/_internals/client.py +13 -5
- classiq/_internals/jobs.py +10 -7
- classiq/analyzer/analyzer.py +26 -28
- classiq/analyzer/analyzer_utilities.py +5 -5
- classiq/analyzer/rb.py +4 -5
- classiq/analyzer/show_interactive_hack.py +6 -6
- classiq/applications/benchmarking/mirror_benchmarking.py +9 -6
- classiq/applications/combinatorial_optimization/__init__.py +5 -0
- classiq/applications/qnn/circuit_utils.py +2 -2
- classiq/applications/qnn/gradients/quantum_gradient.py +2 -2
- classiq/applications/qnn/types.py +2 -2
- classiq/applications/qsvm/qsvm.py +4 -7
- classiq/applications/qsvm/qsvm_data_generation.py +2 -5
- classiq/applications_model_constructors/__init__.py +9 -1
- classiq/applications_model_constructors/chemistry_model_constructor.py +9 -16
- classiq/applications_model_constructors/combinatorial_helpers/__init__.py +0 -0
- classiq/applications_model_constructors/combinatorial_helpers/allowed_constraints.py +20 -0
- classiq/applications_model_constructors/combinatorial_helpers/arithmetic/__init__.py +0 -0
- classiq/applications_model_constructors/combinatorial_helpers/arithmetic/arithmetic_expression.py +35 -0
- classiq/applications_model_constructors/combinatorial_helpers/arithmetic/isolation.py +42 -0
- classiq/applications_model_constructors/combinatorial_helpers/combinatorial_problem_utils.py +130 -0
- classiq/applications_model_constructors/combinatorial_helpers/encoding_mapping.py +107 -0
- classiq/applications_model_constructors/combinatorial_helpers/encoding_utils.py +122 -0
- classiq/applications_model_constructors/combinatorial_helpers/memory.py +79 -0
- classiq/applications_model_constructors/combinatorial_helpers/multiple_comp_basis_sp.py +34 -0
- classiq/applications_model_constructors/combinatorial_helpers/optimization_model.py +166 -0
- classiq/applications_model_constructors/combinatorial_helpers/pauli_helpers/__init__.py +0 -0
- classiq/applications_model_constructors/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +31 -0
- classiq/applications_model_constructors/combinatorial_helpers/pauli_helpers/pauli_utils.py +65 -0
- classiq/applications_model_constructors/combinatorial_helpers/py.typed +0 -0
- classiq/applications_model_constructors/combinatorial_helpers/pyomo_utils.py +243 -0
- classiq/applications_model_constructors/combinatorial_helpers/sympy_utils.py +22 -0
- classiq/applications_model_constructors/combinatorial_helpers/transformations/__init__.py +0 -0
- classiq/applications_model_constructors/combinatorial_helpers/transformations/encoding.py +194 -0
- classiq/applications_model_constructors/combinatorial_helpers/transformations/fixed_variables.py +144 -0
- classiq/applications_model_constructors/combinatorial_helpers/transformations/ising_converter.py +124 -0
- classiq/applications_model_constructors/combinatorial_helpers/transformations/penalty.py +32 -0
- classiq/applications_model_constructors/combinatorial_helpers/transformations/penalty_support.py +41 -0
- classiq/applications_model_constructors/combinatorial_helpers/transformations/sign_seperation.py +75 -0
- classiq/applications_model_constructors/combinatorial_helpers/transformations/slack_variables.py +90 -0
- classiq/applications_model_constructors/combinatorial_optimization_model_constructor.py +48 -91
- classiq/applications_model_constructors/finance_model_constructor.py +4 -17
- classiq/applications_model_constructors/grover_model_constructor.py +20 -91
- classiq/applications_model_constructors/libraries/qmci_library.py +17 -19
- classiq/builtin_functions/standard_gates.py +1 -1
- classiq/exceptions.py +43 -1
- classiq/executor.py +10 -9
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +6 -3
- classiq/interface/analyzer/result.py +12 -4
- classiq/interface/applications/qsvm.py +13 -1
- classiq/interface/backend/backend_preferences.py +4 -2
- classiq/interface/backend/pydantic_backend.py +3 -1
- classiq/interface/backend/quantum_backend_providers.py +1 -0
- classiq/interface/chemistry/fermionic_operator.py +15 -13
- classiq/interface/chemistry/ground_state_problem.py +18 -3
- classiq/interface/chemistry/molecule.py +8 -6
- classiq/interface/chemistry/operator.py +20 -14
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +1 -1
- classiq/interface/combinatorial_optimization/examples/greater_than_ilp.py +1 -1
- classiq/interface/combinatorial_optimization/examples/ilp.py +2 -1
- classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -2
- classiq/interface/combinatorial_optimization/examples/mds.py +2 -1
- classiq/interface/combinatorial_optimization/examples/mht.py +3 -3
- classiq/interface/combinatorial_optimization/examples/mis.py +4 -1
- classiq/interface/combinatorial_optimization/examples/mvc.py +2 -1
- classiq/interface/combinatorial_optimization/examples/set_cover.py +2 -1
- classiq/interface/combinatorial_optimization/examples/tsp.py +4 -3
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +6 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +9 -3
- classiq/interface/executor/aws_execution_cost.py +4 -3
- classiq/interface/executor/estimation.py +2 -2
- classiq/interface/executor/execution_preferences.py +5 -34
- classiq/interface/executor/execution_request.py +19 -17
- classiq/interface/executor/optimizer_preferences.py +22 -13
- classiq/interface/executor/{quantum_program.py → quantum_code.py} +21 -15
- classiq/interface/executor/quantum_instruction_set.py +2 -1
- classiq/interface/executor/register_initialization.py +1 -3
- classiq/interface/executor/result.py +41 -10
- classiq/interface/executor/vqe_result.py +1 -1
- classiq/interface/finance/function_input.py +17 -4
- classiq/interface/finance/gaussian_model_input.py +3 -1
- classiq/interface/finance/log_normal_model_input.py +3 -1
- classiq/interface/finance/model_input.py +2 -0
- classiq/interface/generator/amplitude_loading.py +6 -3
- classiq/interface/generator/application_apis/__init__.py +1 -0
- classiq/interface/generator/application_apis/arithmetic_declarations.py +14 -0
- classiq/interface/generator/arith/argument_utils.py +14 -4
- classiq/interface/generator/arith/arithmetic.py +3 -1
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +12 -13
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -1
- classiq/interface/generator/arith/arithmetic_expression_parser.py +8 -2
- classiq/interface/generator/arith/arithmetic_expression_validator.py +16 -2
- classiq/interface/generator/arith/arithmetic_operations.py +5 -10
- classiq/interface/generator/arith/ast_node_rewrite.py +1 -1
- classiq/interface/generator/arith/binary_ops.py +202 -54
- classiq/interface/generator/arith/extremum_operations.py +5 -3
- classiq/interface/generator/arith/logical_ops.py +4 -2
- classiq/interface/generator/arith/machine_precision.py +3 -0
- classiq/interface/generator/arith/number_utils.py +34 -44
- classiq/interface/generator/arith/register_user_input.py +21 -1
- classiq/interface/generator/arith/unary_ops.py +16 -25
- classiq/interface/generator/chemistry_function_params.py +4 -4
- classiq/interface/generator/commuting_pauli_exponentiation.py +3 -1
- classiq/interface/generator/compiler_keywords.py +4 -0
- classiq/interface/generator/complex_type.py +3 -10
- classiq/interface/generator/control_state.py +5 -3
- classiq/interface/generator/credit_risk_example/linear_gci.py +10 -3
- classiq/interface/generator/credit_risk_example/weighted_adder.py +14 -4
- classiq/interface/generator/expressions/atomic_expression_functions.py +5 -3
- classiq/interface/generator/expressions/evaluated_expression.py +18 -4
- classiq/interface/generator/expressions/expression.py +1 -1
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +33 -0
- classiq/interface/generator/expressions/sympy_supported_expressions.py +2 -1
- classiq/interface/generator/finance.py +1 -1
- classiq/interface/generator/function_params.py +7 -6
- classiq/interface/generator/functions/__init__.py +1 -1
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/std_lib_functions.py +505 -138
- classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +25 -99
- classiq/interface/generator/functions/foreign_function_definition.py +12 -4
- classiq/interface/generator/functions/function_implementation.py +8 -4
- classiq/interface/generator/functions/native_function_definition.py +4 -2
- classiq/interface/generator/functions/register.py +4 -2
- classiq/interface/generator/functions/register_mapping_data.py +14 -10
- classiq/interface/generator/generated_circuit_data.py +2 -2
- classiq/interface/generator/grover_operator.py +5 -3
- classiq/interface/generator/hamiltonian_evolution/suzuki_trotter.py +5 -1
- classiq/interface/generator/hardware/hardware_data.py +6 -4
- classiq/interface/generator/hardware_efficient_ansatz.py +25 -8
- classiq/interface/generator/hartree_fock.py +3 -1
- classiq/interface/generator/linear_pauli_rotations.py +3 -1
- classiq/interface/generator/mcu.py +5 -3
- classiq/interface/generator/mcx.py +7 -5
- classiq/interface/generator/model/constraints.py +2 -1
- classiq/interface/generator/model/model.py +11 -19
- classiq/interface/generator/model/preferences/preferences.py +4 -3
- classiq/interface/generator/oracles/custom_oracle.py +4 -2
- classiq/interface/generator/oracles/oracle_abc.py +2 -2
- classiq/interface/generator/qpe.py +6 -4
- classiq/interface/generator/qsvm.py +5 -8
- classiq/interface/generator/quantum_function_call.py +21 -16
- classiq/interface/generator/{generated_circuit.py → quantum_program.py} +10 -14
- classiq/interface/generator/range_types.py +3 -1
- classiq/interface/generator/slice_parsing_utils.py +8 -3
- classiq/interface/generator/standard_gates/controlled_standard_gates.py +4 -2
- classiq/interface/generator/state_preparation/metrics.py +2 -1
- classiq/interface/generator/state_preparation/state_preparation.py +7 -5
- classiq/interface/generator/state_propagator.py +16 -5
- classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -1
- classiq/interface/generator/types/struct_declaration.py +8 -3
- classiq/interface/generator/ucc.py +6 -4
- classiq/interface/generator/unitary_gate.py +7 -3
- classiq/interface/generator/validations/flow_graph.py +6 -4
- classiq/interface/generator/validations/validator_functions.py +6 -4
- classiq/interface/hardware.py +2 -2
- classiq/interface/helpers/custom_encoders.py +3 -0
- classiq/interface/helpers/pydantic_model_helpers.py +0 -6
- classiq/interface/helpers/validation_helpers.py +1 -1
- classiq/interface/helpers/versioned_model.py +4 -1
- classiq/interface/ide/show.py +2 -2
- classiq/interface/jobs.py +72 -3
- classiq/interface/model/bind_operation.py +18 -11
- classiq/interface/model/call_synthesis_data.py +68 -0
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/model.py +27 -21
- classiq/interface/model/native_function_definition.py +3 -5
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +9 -4
- classiq/interface/model/quantum_expressions/control_state.py +2 -2
- classiq/interface/model/quantum_function_call.py +25 -139
- classiq/interface/model/quantum_function_declaration.py +8 -0
- classiq/interface/model/quantum_if_operation.py +2 -3
- classiq/interface/model/quantum_lambda_function.py +64 -0
- classiq/interface/model/quantum_type.py +57 -56
- classiq/interface/model/quantum_variable_declaration.py +1 -1
- classiq/interface/model/statement_block.py +32 -0
- classiq/interface/model/validations/handles_validator.py +14 -12
- classiq/interface/model/within_apply_operation.py +11 -0
- classiq/interface/pyomo_extension/pyomo_sympy_bimap.py +4 -1
- classiq/interface/server/routes.py +5 -0
- classiq/model/function_handler.py +5 -9
- classiq/model/model.py +2 -19
- classiq/qmod/__init__.py +13 -6
- classiq/qmod/builtins/classical_execution_primitives.py +27 -36
- classiq/qmod/builtins/classical_functions.py +24 -14
- classiq/qmod/builtins/functions.py +162 -145
- classiq/qmod/builtins/operations.py +24 -35
- classiq/qmod/builtins/structs.py +15 -15
- classiq/qmod/cfunc.py +42 -0
- classiq/qmod/classical_function.py +6 -14
- classiq/qmod/declaration_inferrer.py +12 -21
- classiq/qmod/expression_query.py +23 -0
- classiq/qmod/model_state_container.py +2 -0
- classiq/qmod/native/__init__.py +0 -0
- classiq/qmod/native/expression_to_qmod.py +189 -0
- classiq/qmod/native/pretty_printer.py +311 -0
- classiq/qmod/qfunc.py +27 -0
- classiq/qmod/qmod_constant.py +76 -0
- classiq/qmod/qmod_parameter.py +34 -12
- classiq/qmod/qmod_struct.py +3 -3
- classiq/qmod/qmod_variable.py +102 -18
- classiq/qmod/quantum_expandable.py +16 -16
- classiq/qmod/quantum_function.py +37 -8
- classiq/qmod/symbolic.py +47 -4
- classiq/qmod/symbolic_expr.py +9 -0
- classiq/qmod/utilities.py +13 -0
- classiq/qmod/write_qmod.py +39 -0
- classiq/quantum_functions/__init__.py +2 -2
- classiq/quantum_functions/annotation_parser.py +9 -11
- classiq/quantum_functions/function_parser.py +1 -1
- classiq/quantum_functions/quantum_function.py +3 -3
- classiq/quantum_register.py +17 -9
- {classiq-0.37.0.dist-info → classiq-0.38.0.dist-info}/METADATA +2 -1
- {classiq-0.37.0.dist-info → classiq-0.38.0.dist-info}/RECORD +222 -186
- {classiq-0.37.0.dist-info → classiq-0.38.0.dist-info}/WHEEL +1 -1
- classiq/interface/generator/expressions/qmod_qnum_proxy.py +0 -22
- classiq/interface/generator/types/builtin_struct_declarations/qaoa_declarations.py +0 -23
- classiq/interface/generator/types/combinatorial_problem.py +0 -26
- classiq/interface/model/numeric_reinterpretation.py +0 -25
- classiq/interface/model/operator_synthesis_data.py +0 -48
- classiq/model/function_handler.pyi +0 -152
@@ -8,18 +8,12 @@ from classiq.interface.model.bind_operation import BindOperation
|
|
8
8
|
from classiq.interface.model.handle_binding import HandleBinding, SlicedHandleBinding
|
9
9
|
from classiq.interface.model.model import Model, SerializedModel
|
10
10
|
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
11
|
-
from classiq.interface.model.numeric_reinterpretation import (
|
12
|
-
NumericReinterpretationOperation,
|
13
|
-
)
|
14
11
|
from classiq.interface.model.port_declaration import PortDeclaration
|
15
12
|
from classiq.interface.model.quantum_expressions.arithmetic_operation import (
|
16
13
|
ArithmeticOperation,
|
17
14
|
)
|
18
|
-
from classiq.interface.model.quantum_function_call import
|
19
|
-
|
20
|
-
QuantumLambdaFunction,
|
21
|
-
)
|
22
|
-
from classiq.interface.model.quantum_statement import QuantumStatement
|
15
|
+
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
16
|
+
from classiq.interface.model.quantum_lambda_function import QuantumLambdaFunction
|
23
17
|
from classiq.interface.model.quantum_type import QuantumNumeric
|
24
18
|
from classiq.interface.model.variable_declaration_statement import (
|
25
19
|
VariableDeclarationStatement,
|
@@ -32,44 +26,6 @@ _OUTPUT_VARIABLE_NAME = "result"
|
|
32
26
|
_PREDICATE_FUNCTION_NAME = "expr_predicate"
|
33
27
|
|
34
28
|
|
35
|
-
def split_registers(
|
36
|
-
register_names: List[str],
|
37
|
-
register_sizes: List[int],
|
38
|
-
input_wire_name: str,
|
39
|
-
) -> List[QuantumStatement]:
|
40
|
-
if len(register_names) == 0:
|
41
|
-
return []
|
42
|
-
wires = (
|
43
|
-
[input_wire_name]
|
44
|
-
+ [f"split{i}" for i in range(len(register_names) - 2)]
|
45
|
-
+ [register_names[-1]]
|
46
|
-
)
|
47
|
-
|
48
|
-
if len(register_names) == 1:
|
49
|
-
return [
|
50
|
-
BindOperation(
|
51
|
-
in_handle=HandleBinding(name=wires[0]),
|
52
|
-
out_handle=HandleBinding(name=wires[1]),
|
53
|
-
)
|
54
|
-
]
|
55
|
-
|
56
|
-
return [
|
57
|
-
QuantumFunctionCall(
|
58
|
-
function="split",
|
59
|
-
params={
|
60
|
-
"out1_size": Expression(expr=f"{int(register_sizes[i])}"),
|
61
|
-
"out2_size": Expression(expr=f"{int(sum(register_sizes[i + 1:]))}"),
|
62
|
-
},
|
63
|
-
inputs={"in": HandleBinding(name=wires[i])},
|
64
|
-
outputs={
|
65
|
-
"out1": HandleBinding(name=register),
|
66
|
-
"out2": HandleBinding(name=wires[i + 1]),
|
67
|
-
},
|
68
|
-
)
|
69
|
-
for i, register in enumerate(register_names[:-1])
|
70
|
-
]
|
71
|
-
|
72
|
-
|
73
29
|
def _arithmetic_oracle_io_dict(
|
74
30
|
definitions: List[Tuple[str, RegisterUserInput]], handle_name: str
|
75
31
|
) -> Dict[str, HandleBinding]:
|
@@ -89,12 +45,12 @@ def _construct_arithmetic_oracle(
|
|
89
45
|
predicate_function: str,
|
90
46
|
definitions: List[Tuple[str, RegisterUserInput]],
|
91
47
|
) -> QuantumFunctionCall:
|
92
|
-
predicate_var_binding = _arithmetic_oracle_io_dict(definitions, "
|
93
|
-
predicate_var_binding["res"] = HandleBinding(name="
|
48
|
+
predicate_var_binding = _arithmetic_oracle_io_dict(definitions, "arg0")
|
49
|
+
predicate_var_binding["res"] = HandleBinding(name="arg1")
|
94
50
|
return QuantumFunctionCall(
|
95
|
-
function="
|
51
|
+
function="phase_oracle",
|
96
52
|
inouts={
|
97
|
-
"target": HandleBinding(name="
|
53
|
+
"target": HandleBinding(name="arg0"),
|
98
54
|
},
|
99
55
|
operands={
|
100
56
|
"predicate": QuantumLambdaFunction(
|
@@ -117,38 +73,17 @@ def grover_main_port_declarations(
|
|
117
73
|
name: PortDeclaration(
|
118
74
|
name=name,
|
119
75
|
size=Expression(expr=f"{reg.size}"),
|
120
|
-
quantum_type=QuantumNumeric(
|
76
|
+
quantum_type=QuantumNumeric(
|
77
|
+
size=Expression(expr=f"{reg.size}"),
|
78
|
+
is_signed=Expression(expr=f"{reg.is_signed}"),
|
79
|
+
fraction_digits=Expression(expr=f"{reg.fraction_places}"),
|
80
|
+
),
|
121
81
|
direction=direction,
|
122
82
|
)
|
123
83
|
for name, reg in definitions
|
124
84
|
}
|
125
85
|
|
126
86
|
|
127
|
-
def _generate_variable_declaration_statements(
|
128
|
-
definitions: List[Tuple[str, RegisterUserInput]]
|
129
|
-
) -> List[VariableDeclarationStatement]:
|
130
|
-
ret = [VariableDeclarationStatement(name="gsq")]
|
131
|
-
if len(definitions) >= 2:
|
132
|
-
ret += [
|
133
|
-
VariableDeclarationStatement(name=f"split{i}")
|
134
|
-
for i in range(len(definitions) - 2)
|
135
|
-
]
|
136
|
-
return ret
|
137
|
-
|
138
|
-
|
139
|
-
def reinterpret_registers(
|
140
|
-
definitions: List[Tuple[str, RegisterUserInput]]
|
141
|
-
) -> List[QuantumStatement]:
|
142
|
-
return [
|
143
|
-
NumericReinterpretationOperation(
|
144
|
-
target=HandleBinding(name=name),
|
145
|
-
fraction_digits=Expression(expr=f"{definition.fraction_places}"),
|
146
|
-
is_signed=Expression(expr=f"{definition.is_signed}"),
|
147
|
-
)
|
148
|
-
for name, definition in definitions
|
149
|
-
]
|
150
|
-
|
151
|
-
|
152
87
|
def construct_grover_model(
|
153
88
|
definitions: List[Tuple[str, RegisterUserInput]],
|
154
89
|
expression: str,
|
@@ -170,7 +105,6 @@ def construct_grover_model(
|
|
170
105
|
name=_PREDICATE_FUNCTION_NAME,
|
171
106
|
port_declarations=predicate_port_decls,
|
172
107
|
body=[
|
173
|
-
*reinterpret_registers(definitions),
|
174
108
|
ArithmeticOperation(
|
175
109
|
expression=Expression(expr=expression),
|
176
110
|
result_var=HandleBinding(name="res"),
|
@@ -184,23 +118,22 @@ def construct_grover_model(
|
|
184
118
|
definitions, PortDeclarationDirection.Output
|
185
119
|
),
|
186
120
|
body=[
|
187
|
-
|
121
|
+
VariableDeclarationStatement(name="packed_vars"),
|
188
122
|
QuantumFunctionCall(
|
189
123
|
function="allocate",
|
190
124
|
positional_args=[
|
191
125
|
Expression(expr=f"{num_qubits}"),
|
192
|
-
HandleBinding(name="
|
126
|
+
HandleBinding(name="packed_vars"),
|
193
127
|
],
|
194
128
|
),
|
195
129
|
QuantumFunctionCall(
|
196
130
|
function="grover_search",
|
197
131
|
params={
|
198
|
-
"num_qubits": Expression(expr=f"{num_qubits}"),
|
199
132
|
"reps": Expression(expr=f"{num_reps}"),
|
200
133
|
},
|
201
|
-
inouts={"
|
134
|
+
inouts={"packed_vars": HandleBinding(name="packed_vars")},
|
202
135
|
operands={
|
203
|
-
"
|
136
|
+
"oracle": QuantumLambdaFunction(
|
204
137
|
body=[
|
205
138
|
_construct_arithmetic_oracle(
|
206
139
|
_PREDICATE_FUNCTION_NAME,
|
@@ -210,18 +143,14 @@ def construct_grover_model(
|
|
210
143
|
)
|
211
144
|
},
|
212
145
|
),
|
213
|
-
|
214
|
-
[name
|
215
|
-
[
|
216
|
-
|
146
|
+
BindOperation(
|
147
|
+
in_handles=[HandleBinding(name="packed_vars")],
|
148
|
+
out_handles=[
|
149
|
+
HandleBinding(name=name) for name, _ in definitions
|
150
|
+
],
|
217
151
|
),
|
218
|
-
*reinterpret_registers(definitions),
|
219
152
|
],
|
220
153
|
),
|
221
154
|
],
|
222
|
-
classical_execution_code=f"""
|
223
|
-
{_OUTPUT_VARIABLE_NAME} = sample()
|
224
|
-
save({{{_OUTPUT_VARIABLE_NAME!r}: {_OUTPUT_VARIABLE_NAME}}})
|
225
|
-
""",
|
226
155
|
)
|
227
156
|
return grover_model.get_model()
|
@@ -5,13 +5,11 @@ from classiq.interface.generator.functions.port_declaration import (
|
|
5
5
|
from classiq.interface.model.handle_binding import HandleBinding, SlicedHandleBinding
|
6
6
|
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
7
7
|
from classiq.interface.model.port_declaration import PortDeclaration
|
8
|
-
from classiq.interface.model.quantum_function_call import
|
9
|
-
QuantumFunctionCall,
|
10
|
-
QuantumLambdaFunction,
|
11
|
-
)
|
8
|
+
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
12
9
|
from classiq.interface.model.quantum_function_declaration import (
|
13
10
|
QuantumOperandDeclaration,
|
14
11
|
)
|
12
|
+
from classiq.interface.model.quantum_lambda_function import QuantumLambdaFunction
|
15
13
|
|
16
14
|
from classiq import Integer
|
17
15
|
|
@@ -56,28 +54,14 @@ QMCI_LIBRARY = [
|
|
56
54
|
QuantumFunctionCall(
|
57
55
|
function="amplitude_estimation",
|
58
56
|
params={
|
59
|
-
"num_unitary_qubits": Expression(expr="num_unitary_qubits"),
|
60
57
|
"num_phase_qubits": Expression(expr="num_phase_qubits"),
|
58
|
+
"num_unitary_qubits": Expression(expr="num_unitary_qubits"),
|
61
59
|
},
|
62
60
|
outputs={
|
63
61
|
"phase_port": HandleBinding(name="phase_port"),
|
64
62
|
"unitary_port": HandleBinding(name="unitary_port"),
|
65
63
|
},
|
66
64
|
operands={
|
67
|
-
"oracle_op": QuantumLambdaFunction(
|
68
|
-
body=[
|
69
|
-
QuantumFunctionCall(
|
70
|
-
function="Z",
|
71
|
-
inouts={
|
72
|
-
"target": SlicedHandleBinding(
|
73
|
-
name="oq",
|
74
|
-
start=Expression(expr="num_unitary_qubits-1"),
|
75
|
-
end=Expression(expr="num_unitary_qubits"),
|
76
|
-
),
|
77
|
-
},
|
78
|
-
),
|
79
|
-
]
|
80
|
-
),
|
81
65
|
"sp_op": QuantumLambdaFunction(
|
82
66
|
body=[
|
83
67
|
QuantumFunctionCall(
|
@@ -102,6 +86,20 @@ QMCI_LIBRARY = [
|
|
102
86
|
)
|
103
87
|
],
|
104
88
|
),
|
89
|
+
"oracle_op": QuantumLambdaFunction(
|
90
|
+
body=[
|
91
|
+
QuantumFunctionCall(
|
92
|
+
function="Z",
|
93
|
+
inouts={
|
94
|
+
"target": SlicedHandleBinding(
|
95
|
+
name="oq",
|
96
|
+
start=Expression(expr="num_unitary_qubits-1"),
|
97
|
+
end=Expression(expr="num_unitary_qubits"),
|
98
|
+
),
|
99
|
+
},
|
100
|
+
),
|
101
|
+
]
|
102
|
+
),
|
105
103
|
},
|
106
104
|
),
|
107
105
|
],
|
@@ -1 +1 @@
|
|
1
|
-
from classiq.interface.generator.standard_gates.standard_gates_param_list import * # noqa:
|
1
|
+
from classiq.interface.generator.standard_gates.standard_gates_param_list import * # noqa: F403
|
classiq/exceptions.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import logging
|
2
|
-
from typing import List
|
2
|
+
from typing import Iterable, List
|
3
3
|
|
4
4
|
_logger = logging.getLogger(__name__)
|
5
5
|
|
@@ -129,3 +129,45 @@ class ClassiqMismatchIOsError(ClassiqError):
|
|
129
129
|
|
130
130
|
class ClassiqNotImplementedError(ClassiqError, NotImplementedError):
|
131
131
|
pass
|
132
|
+
|
133
|
+
|
134
|
+
class ClassiqCombOptError(ClassiqError):
|
135
|
+
pass
|
136
|
+
|
137
|
+
|
138
|
+
class ClassiqCombOptNoSolutionError(ClassiqError):
|
139
|
+
|
140
|
+
def __init__(self) -> None:
|
141
|
+
super().__init__("There is no valid solution for this optimization problem.")
|
142
|
+
|
143
|
+
|
144
|
+
class ClassiqCombOptTrivialProblemError(ClassiqError):
|
145
|
+
|
146
|
+
def __init__(self, solution: List[int]) -> None:
|
147
|
+
super().__init__(
|
148
|
+
message=f"The problem doesn't have free decision variables. "
|
149
|
+
f"The trivial solution is {solution}."
|
150
|
+
)
|
151
|
+
|
152
|
+
|
153
|
+
class ClassiqCombOptInvalidEncodingTypeError(ClassiqError):
|
154
|
+
|
155
|
+
def __init__(self, encoding_type: str, valid_types: Iterable[str]) -> None:
|
156
|
+
super().__init__(
|
157
|
+
f"Invalid variable encoding type {encoding_type}. "
|
158
|
+
f"The available encoding types are {list(valid_types)}"
|
159
|
+
)
|
160
|
+
|
161
|
+
|
162
|
+
class ClassiqNonNumericCoefficientInPauliError(ClassiqError):
|
163
|
+
pass
|
164
|
+
|
165
|
+
|
166
|
+
class ClassiqCombOptNotSupportedProblemError(ClassiqCombOptError):
|
167
|
+
pass
|
168
|
+
|
169
|
+
|
170
|
+
class ClassiqExecutorInvalidHamiltonianError(ClassiqCombOptError):
|
171
|
+
|
172
|
+
def __init__(self) -> None:
|
173
|
+
super().__init__("Invalid hamiltonian")
|
classiq/executor.py
CHANGED
@@ -13,6 +13,7 @@ from classiq.interface.executor.execution_preferences import ExecutionPreference
|
|
13
13
|
from classiq.interface.executor.execution_request import (
|
14
14
|
EstimateOperatorsExecution,
|
15
15
|
ExecutionRequest,
|
16
|
+
QuantumCodeExecution,
|
16
17
|
)
|
17
18
|
from classiq.interface.executor.execution_result import (
|
18
19
|
ResultsCollection,
|
@@ -20,10 +21,10 @@ from classiq.interface.executor.execution_result import (
|
|
20
21
|
TaggedEstimationResult,
|
21
22
|
TaggedExecutionDetails,
|
22
23
|
)
|
24
|
+
from classiq.interface.executor.quantum_code import MultipleArguments, QuantumCode
|
23
25
|
from classiq.interface.executor.quantum_instruction_set import QuantumInstructionSet
|
24
|
-
from classiq.interface.executor.quantum_program import MultipleArguments, QuantumProgram
|
25
26
|
from classiq.interface.executor.result import ExecutionDetails
|
26
|
-
from classiq.interface.generator.
|
27
|
+
from classiq.interface.generator.quantum_program import QuantumProgram
|
27
28
|
|
28
29
|
from classiq._internals.api_wrapper import ApiWrapper
|
29
30
|
from classiq._internals.async_utils import syncify_function
|
@@ -32,7 +33,7 @@ from classiq.model.model import DEFAULT_RESULT_NAME
|
|
32
33
|
from classiq.synthesis import SerializedQuantumProgram
|
33
34
|
|
34
35
|
BatchExecutionResult: TypeAlias = Union[ExecutionDetails, BaseException]
|
35
|
-
ProgramAndResult: TypeAlias = Tuple[
|
36
|
+
ProgramAndResult: TypeAlias = Tuple[QuantumCode, BatchExecutionResult]
|
36
37
|
BackendPreferencesAndResult: TypeAlias = Tuple[
|
37
38
|
BackendPreferencesTypes, int, BatchExecutionResult
|
38
39
|
]
|
@@ -41,8 +42,8 @@ _MAX_ARGUMENTS_SIZE = 1024
|
|
41
42
|
|
42
43
|
def _parse_serialized_qprog(
|
43
44
|
quantum_program: SerializedQuantumProgram,
|
44
|
-
) ->
|
45
|
-
return
|
45
|
+
) -> QuantumProgram:
|
46
|
+
return QuantumProgram.parse_raw(quantum_program)
|
46
47
|
|
47
48
|
|
48
49
|
async def execute_async(quantum_program: SerializedQuantumProgram) -> ExecutionJob:
|
@@ -55,7 +56,7 @@ execute = syncify_function(execute_async)
|
|
55
56
|
|
56
57
|
|
57
58
|
async def _execute_qnn_async_estimate(
|
58
|
-
quantum_program:
|
59
|
+
quantum_program: QuantumCode,
|
59
60
|
execution_preferences: ExecutionPreferences,
|
60
61
|
observables: PauliOperators,
|
61
62
|
) -> ResultsCollection:
|
@@ -79,11 +80,11 @@ async def _execute_qnn_async_estimate(
|
|
79
80
|
|
80
81
|
|
81
82
|
async def _execute_qnn_async_program(
|
82
|
-
quantum_program:
|
83
|
+
quantum_program: QuantumCode,
|
83
84
|
execution_preferences: ExecutionPreferences,
|
84
85
|
) -> ResultsCollection:
|
85
86
|
request = ExecutionRequest(
|
86
|
-
execution_payload=quantum_program.dict(),
|
87
|
+
execution_payload=QuantumCodeExecution(**quantum_program.dict()),
|
87
88
|
preferences=execution_preferences,
|
88
89
|
)
|
89
90
|
|
@@ -154,7 +155,7 @@ def set_initial_values(
|
|
154
155
|
|
155
156
|
|
156
157
|
__all__ = [
|
157
|
-
"
|
158
|
+
"QuantumCode",
|
158
159
|
"QuantumInstructionSet",
|
159
160
|
"execute_qnn",
|
160
161
|
"OperatorsEstimation",
|
classiq/interface/_version.py
CHANGED
@@ -8,7 +8,9 @@ from classiq.interface.backend.quantum_backend_providers import AnalyzerProvider
|
|
8
8
|
from classiq.interface.chemistry.ground_state_problem import MoleculeProblem
|
9
9
|
from classiq.interface.executor.optimizer_preferences import OptimizerPreferences
|
10
10
|
from classiq.interface.generator.hardware.hardware_data import SynthesisHardwareData
|
11
|
-
from classiq.interface.generator.model.preferences.preferences import
|
11
|
+
from classiq.interface.generator.model.preferences.preferences import (
|
12
|
+
TranspilationOption,
|
13
|
+
)
|
12
14
|
from classiq.interface.hardware import Provider
|
13
15
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonEmptyString
|
14
16
|
|
@@ -44,7 +46,8 @@ class AnalysisOptionalDevicesParams(HardwareListParams):
|
|
44
46
|
|
45
47
|
class AnalysisHardwareTranspilationParams(pydantic.BaseModel):
|
46
48
|
hardware_data: Optional[SynthesisHardwareData]
|
47
|
-
|
49
|
+
random_seed: int
|
50
|
+
transpilation_option: TranspilationOption
|
48
51
|
|
49
52
|
|
50
53
|
class AnalysisHardwareListParams(AnalysisParams, HardwareListParams):
|
@@ -87,7 +90,7 @@ class ChemistryGenerationParams(pydantic.BaseModel):
|
|
87
90
|
def initial_point(self) -> Optional[numpy.ndarray]:
|
88
91
|
if self.optimizer_preferences.initial_point is not None:
|
89
92
|
return numpy.ndarray(
|
90
|
-
self.optimizer_preferences.initial_point # type: ignore
|
93
|
+
self.optimizer_preferences.initial_point # type: ignore[arg-type]
|
91
94
|
)
|
92
95
|
else:
|
93
96
|
return None
|
@@ -1,13 +1,15 @@
|
|
1
|
-
from typing import Dict, List, Optional, Set, Tuple
|
1
|
+
from typing import Dict, List, Literal, Optional, Set, Tuple, Union
|
2
2
|
from uuid import UUID
|
3
3
|
|
4
4
|
import pydantic
|
5
|
-
from pydantic import AnyHttpUrl
|
5
|
+
from pydantic import AnyHttpUrl, Field
|
6
|
+
from typing_extensions import Annotated
|
6
7
|
|
7
8
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonEmptyString
|
8
9
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
9
10
|
|
10
11
|
from classiq._internals.enum_utils import StrEnum
|
12
|
+
from classiq.exceptions import ClassiqValueError
|
11
13
|
|
12
14
|
Match = List[List[int]]
|
13
15
|
|
@@ -18,6 +20,7 @@ class GraphStatus(StrEnum):
|
|
18
20
|
|
19
21
|
|
20
22
|
class GraphResult(VersionedModel):
|
23
|
+
kind: Literal["graph"] = Field(default="graph")
|
21
24
|
details: str
|
22
25
|
|
23
26
|
|
@@ -79,7 +82,7 @@ class HardwareComparisonInformation(pydantic.BaseModel):
|
|
79
82
|
def validate_equal_length(cls, values: Dict[str, list]) -> Dict[str, list]:
|
80
83
|
lengths = list(map(len, values.values()))
|
81
84
|
if len(set(lengths)) != 1:
|
82
|
-
raise
|
85
|
+
raise ClassiqValueError("All lists should have the same length")
|
83
86
|
return values
|
84
87
|
|
85
88
|
|
@@ -103,10 +106,15 @@ class SingleHardwareInformation(pydantic.BaseModel):
|
|
103
106
|
)
|
104
107
|
|
105
108
|
|
106
|
-
class HardwareComparisonData(
|
109
|
+
class HardwareComparisonData(VersionedModel):
|
110
|
+
kind: Literal["hardware_comparison"] = Field(default="hardware_comparison")
|
107
111
|
data: List[SingleHardwareInformation]
|
108
112
|
|
109
113
|
|
114
|
+
HardwareComparisonGraphType = Annotated[
|
115
|
+
Union[HardwareComparisonData, GraphResult], Field(discriminator="kind")
|
116
|
+
]
|
117
|
+
|
110
118
|
_HARDWARE_COMPARISON_TABLE_COLUMNS_NAMES: Dict[str, str] = {
|
111
119
|
s.upper(): s.capitalize() for s in SingleHardwareInformation.__fields__
|
112
120
|
}
|
@@ -1,5 +1,13 @@
|
|
1
1
|
from collections.abc import Sequence
|
2
|
-
from typing import
|
2
|
+
from typing import (
|
3
|
+
TYPE_CHECKING,
|
4
|
+
Any,
|
5
|
+
Iterable as IterableType,
|
6
|
+
List,
|
7
|
+
Optional,
|
8
|
+
Tuple,
|
9
|
+
Union,
|
10
|
+
)
|
3
11
|
|
4
12
|
import numpy as np
|
5
13
|
import pydantic
|
@@ -112,3 +120,7 @@ class QSVMTestResult(VersionedModel):
|
|
112
120
|
|
113
121
|
class QSVMPredictResult(VersionedModel):
|
114
122
|
data: list # serialized np.array
|
123
|
+
|
124
|
+
|
125
|
+
Data = Union[DataList, np.ndarray]
|
126
|
+
Labels = Union[List[Any], np.ndarray]
|
@@ -22,6 +22,8 @@ from classiq.interface.backend.quantum_backend_providers import (
|
|
22
22
|
from classiq.interface.hardware import Provider
|
23
23
|
from classiq.interface.helpers.pydantic_model_helpers import values_with_discriminator
|
24
24
|
|
25
|
+
from classiq.exceptions import ClassiqValueError
|
26
|
+
|
25
27
|
|
26
28
|
class BackendPreferences(BaseModel):
|
27
29
|
# Due to the way the field is currently implemented, i.e. it redefined with different types
|
@@ -103,7 +105,7 @@ class AwsBackendPreferences(BackendPreferences):
|
|
103
105
|
) -> str:
|
104
106
|
s3_bucket_name = s3_bucket_name.strip()
|
105
107
|
if not s3_bucket_name.startswith("amazon-braket-"):
|
106
|
-
raise
|
108
|
+
raise ClassiqValueError('S3 bucket name should start with "amazon-braket-"')
|
107
109
|
return s3_bucket_name
|
108
110
|
|
109
111
|
@pydantic.root_validator(pre=True)
|
@@ -273,7 +275,7 @@ def validate_backend_service_provider(backend_service_provider: Any) -> Provider
|
|
273
275
|
for member in Provider:
|
274
276
|
if member.lower() == backend_service_provider.lower():
|
275
277
|
return Provider(member)
|
276
|
-
raise
|
278
|
+
raise ClassiqValueError(
|
277
279
|
f"""Vendor {backend_service_provider} is not supported.
|
278
280
|
The supported providers are {', '.join(Provider)}."""
|
279
281
|
)
|
@@ -13,6 +13,8 @@ INVALID_EMAIL_OQC: str = "aa@aa.aa"
|
|
13
13
|
INVALID_PASSWORD_OQC: str = "Aa1!Aa1!"
|
14
14
|
MAX_EXECUTION_TIMEOUT_SECONDS = timedelta(hours=4).total_seconds()
|
15
15
|
|
16
|
+
EXECUTION_PARAMETER_PATTERN = "[_a-z][_a-z0-9]*"
|
17
|
+
|
16
18
|
if TYPE_CHECKING:
|
17
19
|
PydanticExecutionTimeout = int
|
18
20
|
PydanticAwsRoleArn = str
|
@@ -46,4 +48,4 @@ else:
|
|
46
48
|
|
47
49
|
PydanticArgumentNameType = pydantic.constr(regex="[_a-zA-Z][_a-zA-Z0-9]*")
|
48
50
|
|
49
|
-
PydanticExecutionParameter = pydantic.constr(regex=
|
51
|
+
PydanticExecutionParameter = pydantic.constr(regex=EXECUTION_PARAMETER_PATTERN)
|
@@ -56,6 +56,7 @@ class AzureQuantumBackendNames(StrEnum):
|
|
56
56
|
RIGETTI_ASPEN3 = "rigetti.qpu.aspen-m-3"
|
57
57
|
RIGETTI_SIMULATOR = "rigetti.sim.qvm"
|
58
58
|
RIGETTI_ANKAA2 = "rigetti.qpu.ankaa-2"
|
59
|
+
RIGETTI_ANKAA9 = "rigetti.qpu.ankaa-9q-1"
|
59
60
|
QCI_MACHINE1 = "qci.machine1"
|
60
61
|
QCI_NOISY_SIMULATOR = "qci.simulator.noisy"
|
61
62
|
QCI_SIMULATOR = "qci.simulator"
|
@@ -10,6 +10,8 @@ from classiq.interface.helpers.hashable_pydantic_base_model import (
|
|
10
10
|
HashablePydanticBaseModel,
|
11
11
|
)
|
12
12
|
|
13
|
+
from classiq.exceptions import ClassiqValueError
|
14
|
+
|
13
15
|
LadderOperator = Tuple[str, int]
|
14
16
|
FermionicOperatorTuple = Tuple["FermionicOperator", float]
|
15
17
|
|
@@ -46,19 +48,19 @@ class FermionicOperator(HashablePydanticBaseModel):
|
|
46
48
|
try: # type: ignore[unreachable] # it is reachable...
|
47
49
|
op = tuple(op)
|
48
50
|
except Exception as exc:
|
49
|
-
raise
|
51
|
+
raise ClassiqValueError("Ladder operator should be a tuple.") from exc
|
50
52
|
if len(op) != 2:
|
51
|
-
raise
|
53
|
+
raise ClassiqValueError(
|
52
54
|
"Ladder operator tuple should be of length two; for example (1, '+')."
|
53
55
|
)
|
54
56
|
|
55
57
|
if op[0] not in ("+", "-"):
|
56
|
-
raise
|
58
|
+
raise ClassiqValueError(
|
57
59
|
"The first term in a ladder operator tuple indicates if its a raising ('+')"
|
58
60
|
f" or lowering ('-') operator. Allowed input is: '+' or '-', received {op[0]}"
|
59
61
|
)
|
60
62
|
if not isinstance(op[1], int):
|
61
|
-
raise
|
63
|
+
raise ClassiqValueError(
|
62
64
|
"The second term in a ladder operator tuple indicates its index and should be of type int"
|
63
65
|
)
|
64
66
|
|
@@ -71,7 +73,7 @@ class FermionicOperator(HashablePydanticBaseModel):
|
|
71
73
|
def __mul__(self, coeff: Union[float, int]) -> SummedFermionicOperator:
|
72
74
|
if isinstance(coeff, (float, int)):
|
73
75
|
return SummedFermionicOperator(op_list=[(self, float(coeff))])
|
74
|
-
raise
|
76
|
+
raise ClassiqValueError(
|
75
77
|
"The coefficient multiplying Fermionic Operator should be of type float"
|
76
78
|
)
|
77
79
|
|
@@ -84,7 +86,7 @@ class FermionicOperator(HashablePydanticBaseModel):
|
|
84
86
|
return SummedFermionicOperator(op_list=[(self, 1.0)] + other.op_list)
|
85
87
|
elif isinstance(other, FermionicOperator):
|
86
88
|
return SummedFermionicOperator(op_list=[(self, 1.0)] + [(other, 1.0)])
|
87
|
-
raise
|
89
|
+
raise ClassiqValueError(
|
88
90
|
"FermionicOperator can be summed together only with type FermionicOperator or SummedFermionicOperator"
|
89
91
|
)
|
90
92
|
|
@@ -135,21 +137,21 @@ class SummedFermionicOperator(HashablePydanticBaseModel):
|
|
135
137
|
try: # type: ignore[unreachable] # it is reachable...
|
136
138
|
op = tuple(op)
|
137
139
|
except Exception as exc:
|
138
|
-
raise
|
140
|
+
raise ClassiqValueError("Operator should be a tuple.") from exc
|
139
141
|
if len(op) != 2:
|
140
|
-
raise
|
142
|
+
raise ClassiqValueError("Operator tuple should be of length two.")
|
141
143
|
|
142
144
|
# is it FermionicOperator - if not, convert to FermionicOperator
|
143
|
-
if
|
145
|
+
if not isinstance(op[0], FermionicOperator):
|
144
146
|
try:
|
145
147
|
op = (FermionicOperator(**op[0]), op[1])
|
146
148
|
except Exception as exc:
|
147
|
-
raise
|
149
|
+
raise ClassiqValueError(
|
148
150
|
"The first term in the operator tuple should be an instance of the FermionicOperator class"
|
149
151
|
) from exc
|
150
152
|
|
151
|
-
if
|
152
|
-
raise
|
153
|
+
if not isinstance(op[1], float):
|
154
|
+
raise ClassiqValueError(
|
153
155
|
"The second term in the operator tuple indicates its coefficient and should be of type float"
|
154
156
|
)
|
155
157
|
|
@@ -166,7 +168,7 @@ class SummedFermionicOperator(HashablePydanticBaseModel):
|
|
166
168
|
return SummedFermionicOperator(op_list=self.op_list + other.op_list)
|
167
169
|
elif isinstance(other, FermionicOperator):
|
168
170
|
return SummedFermionicOperator(op_list=self.op_list + [(other, 1.0)])
|
169
|
-
raise
|
171
|
+
raise ClassiqValueError(
|
170
172
|
"FermionicOperator can be summed together only with type FermionicOperator or SummedFermionicOperator"
|
171
173
|
)
|
172
174
|
|