classiq 0.92.0__py3-none-any.whl → 0.99.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 +11 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +31 -142
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +41 -15
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +33 -52
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +9 -9
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +19 -5
- classiq/_internals/help.py +1 -2
- classiq/_internals/host_checker.py +3 -3
- classiq/_internals/jobs.py +14 -14
- classiq/_internals/type_validation.py +3 -3
- classiq/analyzer/analyzer.py +18 -18
- classiq/analyzer/rb.py +17 -8
- classiq/analyzer/show_interactive_hack.py +1 -1
- classiq/applications/__init__.py +2 -2
- classiq/applications/chemistry/__init__.py +0 -30
- classiq/applications/chemistry/op_utils.py +4 -4
- classiq/applications/chemistry/problems.py +3 -3
- classiq/applications/chemistry/ucc.py +1 -2
- classiq/applications/chemistry/z2_symmetries.py +4 -4
- classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
- classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
- classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
- classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
- classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
- classiq/applications/iqae/iqae.py +14 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
- classiq/applications/qnn/qlayer.py +9 -8
- classiq/applications/qnn/torch_utils.py +5 -6
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/__init__.py +20 -2
- classiq/applications/qsp/qsp.py +239 -11
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +20 -12
- classiq/evaluators/qmod_annotated_expression.py +31 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
- classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
- classiq/evaluators/qmod_node_evaluators/binary_op_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +14 -4
- classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
- classiq/execution/__init__.py +0 -3
- classiq/execution/execution_session.py +28 -21
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +71 -37
- classiq/executor.py +1 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +4 -4
- classiq/interface/analyzer/cytoscape_graph.py +3 -3
- classiq/interface/analyzer/result.py +4 -4
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +26 -50
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/backend/provider_config/__init__.py +0 -0
- classiq/interface/backend/provider_config/provider_config.py +8 -0
- classiq/interface/backend/provider_config/providers/__init__.py +0 -0
- classiq/interface/backend/provider_config/providers/alice_bob.py +47 -0
- classiq/interface/backend/provider_config/providers/aqt.py +16 -0
- classiq/interface/backend/provider_config/providers/azure.py +37 -0
- classiq/interface/backend/provider_config/providers/braket.py +39 -0
- classiq/interface/backend/provider_config/providers/ibm.py +26 -0
- classiq/interface/backend/provider_config/providers/ionq.py +22 -0
- classiq/interface/backend/quantum_backend_providers.py +20 -2
- classiq/interface/chemistry/ansatz_library.py +3 -5
- classiq/interface/chemistry/operator.py +3 -3
- classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
- classiq/interface/compression_utils.py +2 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +10 -7
- classiq/interface/execution/primitives.py +6 -6
- classiq/interface/executor/estimate_cost.py +1 -1
- classiq/interface/executor/execution_preferences.py +3 -5
- classiq/interface/executor/execution_request.py +10 -10
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/quantum_code.py +8 -8
- classiq/interface/executor/result.py +28 -18
- classiq/interface/executor/user_budget.py +25 -17
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -3
- classiq/interface/generator/arith/arithmetic.py +2 -2
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
- classiq/interface/generator/arith/arithmetic_operations.py +4 -6
- classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
- classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
- classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
- classiq/interface/generator/arith/binary_ops.py +15 -40
- classiq/interface/generator/arith/logical_ops.py +2 -3
- classiq/interface/generator/arith/number_utils.py +2 -2
- classiq/interface/generator/arith/register_user_input.py +3 -3
- classiq/interface/generator/arith/unary_ops.py +2 -2
- classiq/interface/generator/circuit_code/circuit_code.py +8 -10
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +2 -2
- classiq/interface/generator/copy.py +1 -3
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
- classiq/interface/generator/expressions/evaluated_expression.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
- classiq/interface/generator/function_param_list.py +0 -40
- classiq/interface/generator/function_params.py +5 -6
- classiq/interface/generator/functions/classical_function_declaration.py +2 -2
- classiq/interface/generator/functions/classical_type.py +3 -3
- classiq/interface/generator/functions/type_modifier.py +0 -15
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +14 -18
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
- classiq/interface/generator/hardware/hardware_data.py +8 -8
- classiq/interface/generator/hardware_efficient_ansatz.py +9 -9
- classiq/interface/generator/mcu.py +3 -3
- classiq/interface/generator/mcx.py +3 -3
- classiq/interface/generator/model/constraints.py +34 -5
- classiq/interface/generator/model/preferences/preferences.py +15 -21
- classiq/interface/generator/model/quantum_register.py +7 -10
- classiq/interface/generator/noise_properties.py +3 -7
- classiq/interface/generator/parameters.py +1 -1
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
- classiq/interface/generator/quantum_function_call.py +9 -12
- classiq/interface/generator/quantum_program.py +10 -23
- classiq/interface/generator/range_types.py +3 -3
- classiq/interface/generator/slice_parsing_utils.py +4 -5
- classiq/interface/generator/standard_gates/standard_gates.py +2 -4
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +9 -0
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +12 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -145
- classiq/interface/generator/types/compilation_metadata.py +12 -1
- classiq/interface/generator/types/enum_declaration.py +2 -1
- classiq/interface/generator/validations/flow_graph.py +3 -3
- classiq/interface/generator/visitor.py +10 -12
- classiq/interface/hardware.py +2 -3
- classiq/interface/helpers/classproperty.py +2 -2
- classiq/interface/helpers/custom_encoders.py +2 -1
- classiq/interface/helpers/custom_pydantic_types.py +1 -1
- classiq/interface/helpers/text_utils.py +1 -4
- classiq/interface/ide/visual_model.py +6 -5
- classiq/interface/interface_version.py +1 -1
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +6 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +8 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/power.py +4 -0
- classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
- classiq/interface/model/quantum_function_call.py +3 -6
- classiq/interface/model/quantum_function_declaration.py +1 -0
- classiq/interface/model/quantum_lambda_function.py +4 -4
- classiq/interface/model/quantum_statement.py +11 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -16
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +11 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +30 -27
- classiq/model_expansions/capturing/captured_vars.py +3 -3
- classiq/model_expansions/capturing/mangling_utils.py +1 -2
- classiq/model_expansions/closure.py +12 -11
- classiq/model_expansions/function_builder.py +14 -6
- classiq/model_expansions/generative_functions.py +7 -12
- classiq/model_expansions/interpreters/base_interpreter.py +3 -7
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- classiq/model_expansions/interpreters/generative_interpreter.py +8 -4
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +8 -4
- classiq/model_expansions/quantum_operations/call_emitter.py +31 -37
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
- classiq/model_expansions/quantum_operations/emitter.py +3 -5
- classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
- classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
- classiq/model_expansions/quantum_operations/variable_decleration.py +61 -29
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +6 -6
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +328 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +28 -11
- classiq/open_library/functions/amplitude_loading.py +81 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +19 -14
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/lcu.py +47 -18
- classiq/open_library/functions/modular_exponentiation.py +93 -8
- classiq/open_library/functions/qsvt.py +66 -79
- classiq/open_library/functions/qsvt_temp.py +536 -0
- classiq/open_library/functions/state_preparation.py +130 -27
- classiq/qmod/__init__.py +6 -4
- classiq/qmod/builtins/classical_execution_primitives.py +4 -23
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +15 -153
- classiq/qmod/builtins/functions/__init__.py +9 -18
- classiq/qmod/builtins/functions/allocation.py +25 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/exponentiation.py +51 -2
- classiq/qmod/builtins/functions/mcx_func.py +7 -0
- classiq/qmod/builtins/functions/standard_gates.py +46 -27
- classiq/qmod/builtins/operations.py +173 -79
- classiq/qmod/builtins/structs.py +24 -91
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/classical_variable.py +4 -2
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/expression_query.py +7 -4
- classiq/qmod/model_state_container.py +2 -2
- classiq/qmod/native/pretty_printer.py +25 -14
- classiq/qmod/pretty_print/expression_to_python.py +5 -3
- classiq/qmod/pretty_print/pretty_printer.py +39 -17
- classiq/qmod/python_classical_type.py +40 -13
- classiq/qmod/qfunc.py +124 -19
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -46
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +33 -26
- classiq/qmod/quantum_function.py +84 -36
- classiq/qmod/semantics/annotation/call_annotation.py +5 -5
- classiq/qmod/semantics/error_manager.py +12 -14
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/symbolic_expr.py +12 -4
- classiq/qmod/utilities.py +13 -20
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.92.0.dist-info → classiq-0.99.0.dist-info}/METADATA +38 -37
- {classiq-0.92.0.dist-info → classiq-0.99.0.dist-info}/RECORD +273 -300
- classiq-0.99.0.dist-info/WHEEL +4 -0
- classiq-0.99.0.dist-info/licenses/LICENSE.txt +27 -0
- classiq/applications/chemistry/ansatz_parameters.py +0 -29
- classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
- classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
- classiq/applications/chemistry/ground_state_problem.py +0 -42
- classiq/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/execution/iqcc.py +0 -128
- classiq/interface/applications/qsvm.py +0 -117
- classiq/interface/chemistry/elements.py +0 -120
- classiq/interface/chemistry/fermionic_operator.py +0 -208
- classiq/interface/chemistry/ground_state_problem.py +0 -132
- classiq/interface/chemistry/ground_state_result.py +0 -8
- classiq/interface/chemistry/molecule.py +0 -71
- classiq/interface/execution/iqcc.py +0 -44
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- classiq/interface/generator/chemistry_function_params.py +0 -50
- classiq/interface/generator/entangler_params.py +0 -72
- classiq/interface/generator/entanglers.py +0 -14
- classiq/interface/generator/hamiltonian_evolution/qdrift.py +0 -27
- classiq/interface/generator/hartree_fock.py +0 -26
- classiq/interface/generator/hva.py +0 -22
- classiq/interface/generator/linear_pauli_rotations.py +0 -92
- classiq/interface/generator/qft.py +0 -37
- classiq/interface/generator/qsvm.py +0 -96
- classiq/interface/generator/state_preparation/__init__.py +0 -14
- classiq/interface/generator/state_preparation/bell_state_preparation.py +0 -27
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +0 -28
- classiq/interface/generator/state_preparation/distributions.py +0 -53
- classiq/interface/generator/state_preparation/exponential_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/ghz_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/metrics.py +0 -41
- classiq/interface/generator/state_preparation/state_preparation.py +0 -113
- classiq/interface/generator/state_preparation/state_preparation_abc.py +0 -24
- classiq/interface/generator/state_preparation/uniform_distibution_state_preparation.py +0 -13
- classiq/interface/generator/state_preparation/w_state_preparation.py +0 -13
- classiq/interface/generator/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/open_library/functions/lookup_table.py +0 -58
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- classiq-0.92.0.dist-info/WHEEL +0 -4
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
1
|
import pydantic
|
|
4
2
|
|
|
5
3
|
from classiq.interface.exceptions import ClassiqMissingOutputFormatError
|
|
@@ -26,31 +24,31 @@ class CircuitCodeInterface(pydantic.BaseModel):
|
|
|
26
24
|
return {key: LongStr(value) for key, value in outputs.items()}
|
|
27
25
|
|
|
28
26
|
@property
|
|
29
|
-
def qasm(self) ->
|
|
27
|
+
def qasm(self) -> Code | None:
|
|
30
28
|
return self.outputs.get(QuantumFormat.QASM)
|
|
31
29
|
|
|
32
30
|
@property
|
|
33
|
-
def qsharp(self) ->
|
|
31
|
+
def qsharp(self) -> Code | None:
|
|
34
32
|
return self.outputs.get(QuantumFormat.QSHARP)
|
|
35
33
|
|
|
36
34
|
@property
|
|
37
|
-
def qir(self) ->
|
|
35
|
+
def qir(self) -> Code | None:
|
|
38
36
|
return self.outputs.get(QuantumFormat.QIR)
|
|
39
37
|
|
|
40
38
|
@property
|
|
41
|
-
def ionq(self) ->
|
|
39
|
+
def ionq(self) -> Code | None:
|
|
42
40
|
return self.outputs.get(QuantumFormat.IONQ)
|
|
43
41
|
|
|
44
42
|
@property
|
|
45
|
-
def cirq_json(self) ->
|
|
43
|
+
def cirq_json(self) -> Code | None:
|
|
46
44
|
return self.outputs.get(QuantumFormat.CIRQ_JSON)
|
|
47
45
|
|
|
48
46
|
@property
|
|
49
|
-
def qasm_cirq_compatible(self) ->
|
|
47
|
+
def qasm_cirq_compatible(self) -> Code | None:
|
|
50
48
|
return self.outputs.get(QuantumFormat.QASM_CIRQ_COMPATIBLE)
|
|
51
49
|
|
|
52
50
|
@property
|
|
53
|
-
def _execution_serialization(self) ->
|
|
51
|
+
def _execution_serialization(self) -> Code | None:
|
|
54
52
|
return self.outputs.get(QuantumFormat.EXECUTION_SERIALIZATION)
|
|
55
53
|
|
|
56
54
|
def get_code(self, instruction_set: QuantumInstructionSet) -> Code:
|
|
@@ -60,7 +58,7 @@ class CircuitCodeInterface(pydantic.BaseModel):
|
|
|
60
58
|
raise ClassiqMissingOutputFormatError(missing_formats=[quantum_format])
|
|
61
59
|
return code
|
|
62
60
|
|
|
63
|
-
def get_code_by_priority(self) ->
|
|
61
|
+
def get_code_by_priority(self) -> CodeAndSyntax | None:
|
|
64
62
|
for instruction_set, quantum_format in INSTRUCTION_SET_TO_FORMAT.items():
|
|
65
63
|
code = self.outputs.get(quantum_format)
|
|
66
64
|
if code is not None:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
from typing import Annotated
|
|
1
|
+
from typing import Annotated
|
|
2
2
|
|
|
3
3
|
from pydantic import PlainSerializer, PlainValidator
|
|
4
4
|
from pydantic.json_schema import WithJsonSchema
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def validate_complex(v:
|
|
7
|
+
def validate_complex(v: complex | str) -> complex:
|
|
8
8
|
if isinstance(v, str):
|
|
9
9
|
v = "".join(v.split())
|
|
10
10
|
return complex(v)
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
1
|
import pydantic
|
|
4
2
|
|
|
5
3
|
from classiq.interface.generator.arith import argument_utils
|
|
@@ -10,7 +8,7 @@ from classiq.interface.generator.function_params import FunctionParams
|
|
|
10
8
|
class Copy(FunctionParams):
|
|
11
9
|
source: argument_utils.RegisterOrConst
|
|
12
10
|
target: RegisterArithmeticInfo
|
|
13
|
-
output_size:
|
|
11
|
+
output_size: pydantic.PositiveInt | None = pydantic.Field(default=None)
|
|
14
12
|
|
|
15
13
|
@property
|
|
16
14
|
def source_size(self) -> int:
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
SUPPORTED_PYTHON_BUILTIN_FUNCTIONS = {"len", "sum", "print"}
|
|
2
2
|
|
|
3
3
|
CLASSIQ_BUILTIN_CLASSICAL_FUNCTIONS = {
|
|
4
|
-
"hypercube_entangler_graph",
|
|
5
|
-
"grid_entangler_graph",
|
|
6
4
|
"qft_const_adder_phase",
|
|
7
|
-
"molecule_problem_to_hamiltonian",
|
|
8
|
-
"fock_hamiltonian_problem_to_hamiltonian",
|
|
9
|
-
"molecule_ground_state_solution_post_process",
|
|
10
5
|
}
|
|
11
6
|
|
|
12
7
|
CLASSIQ_EXPR_FUNCTIONS = {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import re
|
|
2
2
|
from collections.abc import Mapping
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
-
from typing import Any,
|
|
4
|
+
from typing import Any, get_args
|
|
5
5
|
|
|
6
6
|
from sympy import Expr
|
|
7
|
-
from typing_extensions import get_args
|
|
8
7
|
|
|
9
8
|
from classiq.interface.backend.pydantic_backend import EXECUTION_PARAMETER_PATTERN
|
|
10
9
|
from classiq.interface.exceptions import ClassiqValueError
|
|
@@ -21,7 +20,7 @@ from classiq.interface.generator.expressions.proxies.classical.qmod_struct_insta
|
|
|
21
20
|
class EvaluatedExpression:
|
|
22
21
|
value: ExpressionValue
|
|
23
22
|
|
|
24
|
-
def is_constant(self, constant_type:
|
|
23
|
+
def is_constant(self, constant_type: type | None = None) -> bool:
|
|
25
24
|
return isinstance(
|
|
26
25
|
self.value,
|
|
27
26
|
get_args(RuntimeConstant) if constant_type is None else constant_type,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ast
|
|
2
2
|
from collections.abc import Mapping
|
|
3
|
-
from typing import Any
|
|
3
|
+
from typing import Any
|
|
4
4
|
|
|
5
5
|
import pydantic
|
|
6
6
|
from pydantic import ConfigDict, PrivateAttr
|
|
@@ -24,7 +24,7 @@ from classiq.interface.generator.function_params import validate_expression_str
|
|
|
24
24
|
|
|
25
25
|
class Expression(HashableASTNode):
|
|
26
26
|
expr: str
|
|
27
|
-
_evaluated_expr:
|
|
27
|
+
_evaluated_expr: EvaluatedExpression | None = PrivateAttr(default=None)
|
|
28
28
|
|
|
29
29
|
def __init__(self, **kwargs: Any) -> None:
|
|
30
30
|
super().__init__(**kwargs)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
from collections.abc import Mapping
|
|
2
|
-
from typing import TYPE_CHECKING, Any, Optional,
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Optional, TypeGuard
|
|
3
3
|
|
|
4
4
|
import sympy
|
|
5
5
|
from sympy import Integer
|
|
6
|
-
from typing_extensions import TypeGuard
|
|
7
6
|
|
|
8
7
|
from classiq.interface.exceptions import ClassiqIndexError
|
|
9
8
|
from classiq.interface.generator.expressions.expression import Expression
|
|
@@ -24,7 +23,7 @@ if TYPE_CHECKING:
|
|
|
24
23
|
)
|
|
25
24
|
|
|
26
25
|
|
|
27
|
-
def _is_int(val: Any) -> TypeGuard[
|
|
26
|
+
def _is_int(val: Any) -> TypeGuard[int | sympy.Basic]:
|
|
28
27
|
if isinstance(val, sympy.Basic):
|
|
29
28
|
return val.is_Number
|
|
30
29
|
return isinstance(val, int)
|
|
@@ -47,7 +46,7 @@ class ClassicalSequenceProxy(NonSymbolicExpr, ClassicalProxy):
|
|
|
47
46
|
raise NotImplementedError
|
|
48
47
|
|
|
49
48
|
def __getitem__(
|
|
50
|
-
self, key:
|
|
49
|
+
self, key: slice | int | Integer | ClassicalProxy
|
|
51
50
|
) -> ClassicalProxy:
|
|
52
51
|
return (
|
|
53
52
|
self._get_slice(key) if isinstance(key, slice) else self._get_subscript(key)
|
|
@@ -68,9 +67,7 @@ class ClassicalSequenceProxy(NonSymbolicExpr, ClassicalProxy):
|
|
|
68
67
|
def get_slice_at(self, start: Any, stop: Any) -> ClassicalProxy:
|
|
69
68
|
raise NotImplementedError
|
|
70
69
|
|
|
71
|
-
def _get_subscript(
|
|
72
|
-
self, index_: Union[int, Integer, ClassicalProxy]
|
|
73
|
-
) -> ClassicalProxy:
|
|
70
|
+
def _get_subscript(self, index_: int | Integer | ClassicalProxy) -> ClassicalProxy:
|
|
74
71
|
if _is_int(index_):
|
|
75
72
|
index = int(index_)
|
|
76
73
|
if index < 0:
|
|
@@ -7,7 +7,6 @@ from classiq.interface.generator.arith.binary_ops import (
|
|
|
7
7
|
BitwiseAnd,
|
|
8
8
|
BitwiseOr,
|
|
9
9
|
BitwiseXor,
|
|
10
|
-
CyclicShift,
|
|
11
10
|
Equal,
|
|
12
11
|
GreaterEqual,
|
|
13
12
|
GreaterThan,
|
|
@@ -28,61 +27,32 @@ from classiq.interface.generator.commuting_pauli_exponentiation import (
|
|
|
28
27
|
CommutingPauliExponentiation,
|
|
29
28
|
)
|
|
30
29
|
from classiq.interface.generator.copy import Copy
|
|
31
|
-
from classiq.interface.generator.entangler_params import (
|
|
32
|
-
GridEntangler,
|
|
33
|
-
HypercubeEntangler,
|
|
34
|
-
TwoDimensionalEntangler,
|
|
35
|
-
)
|
|
36
30
|
from classiq.interface.generator.function_param_library import FunctionParamLibrary
|
|
37
31
|
from classiq.interface.generator.hadamard_transform import HadamardTransform
|
|
38
32
|
from classiq.interface.generator.hamiltonian_evolution.exponentiation import (
|
|
39
33
|
Exponentiation,
|
|
40
34
|
)
|
|
41
|
-
from classiq.interface.generator.hamiltonian_evolution.qdrift import QDrift
|
|
42
35
|
from classiq.interface.generator.hamiltonian_evolution.suzuki_trotter import (
|
|
43
36
|
SuzukiTrotter,
|
|
44
37
|
)
|
|
45
38
|
from classiq.interface.generator.hardware_efficient_ansatz import (
|
|
46
39
|
HardwareEfficientAnsatz,
|
|
47
40
|
)
|
|
48
|
-
from classiq.interface.generator.hartree_fock import HartreeFock
|
|
49
|
-
from classiq.interface.generator.hva import HVA
|
|
50
41
|
from classiq.interface.generator.identity import Identity
|
|
51
|
-
from classiq.interface.generator.linear_pauli_rotations import LinearPauliRotations
|
|
52
42
|
from classiq.interface.generator.mcu import Mcu
|
|
53
43
|
from classiq.interface.generator.mcx import Mcx
|
|
54
|
-
from classiq.interface.generator.qft import QFT
|
|
55
|
-
from classiq.interface.generator.qsvm import QSVMFeatureMap
|
|
56
44
|
from classiq.interface.generator.randomized_benchmarking import RandomizedBenchmarking
|
|
57
45
|
from classiq.interface.generator.reset import Reset
|
|
58
46
|
from classiq.interface.generator.standard_gates.standard_gates_param_list import (
|
|
59
47
|
standard_gate_function_param_library,
|
|
60
48
|
)
|
|
61
49
|
from classiq.interface.generator.standard_gates.u_gate import UGate
|
|
62
|
-
from classiq.interface.generator.state_preparation import (
|
|
63
|
-
BellStatePreparation,
|
|
64
|
-
ComputationalBasisStatePreparation,
|
|
65
|
-
ExponentialStatePreparation,
|
|
66
|
-
GHZStatePreparation,
|
|
67
|
-
StatePreparation,
|
|
68
|
-
UniformDistributionStatePreparation,
|
|
69
|
-
WStatePreparation,
|
|
70
|
-
)
|
|
71
|
-
from classiq.interface.generator.ucc import UCC
|
|
72
50
|
from classiq.interface.generator.unitary_gate import UnitaryGate
|
|
73
51
|
from classiq.interface.generator.user_defined_function_params import CustomFunction
|
|
74
52
|
|
|
75
53
|
function_param_library: FunctionParamLibrary = FunctionParamLibrary(
|
|
76
54
|
param_list=itertools.chain(
|
|
77
55
|
{
|
|
78
|
-
StatePreparation,
|
|
79
|
-
ComputationalBasisStatePreparation,
|
|
80
|
-
UniformDistributionStatePreparation,
|
|
81
|
-
BellStatePreparation,
|
|
82
|
-
GHZStatePreparation,
|
|
83
|
-
WStatePreparation,
|
|
84
|
-
ExponentialStatePreparation,
|
|
85
|
-
QFT,
|
|
86
56
|
BitwiseAnd,
|
|
87
57
|
BitwiseOr,
|
|
88
58
|
BitwiseXor,
|
|
@@ -102,33 +72,23 @@ function_param_library: FunctionParamLibrary = FunctionParamLibrary(
|
|
|
102
72
|
Subtractor,
|
|
103
73
|
RShift,
|
|
104
74
|
LShift,
|
|
105
|
-
CyclicShift,
|
|
106
75
|
Modulo,
|
|
107
|
-
TwoDimensionalEntangler,
|
|
108
|
-
HypercubeEntangler,
|
|
109
|
-
GridEntangler,
|
|
110
76
|
Mcx,
|
|
111
77
|
Mcu,
|
|
112
78
|
CustomFunction,
|
|
113
79
|
HardwareEfficientAnsatz,
|
|
114
80
|
UnitaryGate,
|
|
115
|
-
LinearPauliRotations,
|
|
116
81
|
Multiplier,
|
|
117
82
|
Power,
|
|
118
|
-
HartreeFock,
|
|
119
|
-
UCC,
|
|
120
83
|
Min,
|
|
121
84
|
Max,
|
|
122
85
|
Exponentiation,
|
|
123
86
|
CommutingPauliExponentiation,
|
|
124
87
|
SuzukiTrotter,
|
|
125
|
-
QDrift,
|
|
126
88
|
Identity,
|
|
127
89
|
RandomizedBenchmarking,
|
|
128
|
-
HVA,
|
|
129
90
|
UGate,
|
|
130
91
|
AmplitudeLoading,
|
|
131
|
-
QSVMFeatureMap,
|
|
132
92
|
HadamardTransform,
|
|
133
93
|
Copy,
|
|
134
94
|
Reset,
|
|
@@ -5,7 +5,6 @@ from collections.abc import Collection, Iterable, Mapping
|
|
|
5
5
|
from typing import (
|
|
6
6
|
Annotated,
|
|
7
7
|
Any,
|
|
8
|
-
Optional,
|
|
9
8
|
Union,
|
|
10
9
|
get_args,
|
|
11
10
|
)
|
|
@@ -108,7 +107,7 @@ GenerationExpressionSupportedNodeTypes = Union[
|
|
|
108
107
|
|
|
109
108
|
|
|
110
109
|
def validate_expression_str(
|
|
111
|
-
expr_str: str, supported_functions:
|
|
110
|
+
expr_str: str, supported_functions: set[str] | None = None
|
|
112
111
|
) -> None:
|
|
113
112
|
# By default, no functions are allowed.
|
|
114
113
|
supported_functions = supported_functions or set()
|
|
@@ -219,7 +218,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
|
219
218
|
and (len(output_names - input_names) <= 1)
|
|
220
219
|
)
|
|
221
220
|
|
|
222
|
-
def get_power_order(self) ->
|
|
221
|
+
def get_power_order(self) -> int | None:
|
|
223
222
|
return None
|
|
224
223
|
|
|
225
224
|
def _create_ios(self) -> None:
|
|
@@ -227,7 +226,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
|
227
226
|
|
|
228
227
|
@staticmethod
|
|
229
228
|
def _get_size_of_ios(
|
|
230
|
-
registers: Collection[
|
|
229
|
+
registers: Collection[RegisterArithmeticInfo | None],
|
|
231
230
|
) -> int:
|
|
232
231
|
return sum(reg.size if reg is not None else 0 for reg in registers)
|
|
233
232
|
|
|
@@ -265,11 +264,11 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
|
265
264
|
def parse_function_params(
|
|
266
265
|
*,
|
|
267
266
|
params: Any,
|
|
268
|
-
discriminator:
|
|
267
|
+
discriminator: Any | None,
|
|
269
268
|
param_classes: Collection[type[FunctionParams]],
|
|
270
269
|
no_discriminator_error: Exception,
|
|
271
270
|
bad_function_error: Exception,
|
|
272
|
-
default_parser_class:
|
|
271
|
+
default_parser_class: type[FunctionParams] | None = None,
|
|
273
272
|
) -> FunctionParams: # Any is for use in pydantic validators.
|
|
274
273
|
if not discriminator:
|
|
275
274
|
raise no_discriminator_error
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
|
-
from typing import ClassVar
|
|
2
|
+
from typing import ClassVar
|
|
3
3
|
|
|
4
4
|
import pydantic
|
|
5
5
|
|
|
@@ -23,7 +23,7 @@ class ClassicalFunctionDeclaration(FunctionDeclaration):
|
|
|
23
23
|
default_factory=list,
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
-
return_type:
|
|
26
|
+
return_type: ConcreteClassicalType | None = pydantic.Field(
|
|
27
27
|
description="The type of the classical value that is returned by the function (for classical functions)",
|
|
28
28
|
default=None,
|
|
29
29
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from itertools import chain
|
|
2
|
-
from typing import TYPE_CHECKING, Any, Literal
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Literal
|
|
3
3
|
|
|
4
4
|
import pydantic
|
|
5
5
|
from pydantic import PrivateAttr
|
|
@@ -131,7 +131,7 @@ class StructMetaType(ClassicalType):
|
|
|
131
131
|
class ClassicalArray(ClassicalType):
|
|
132
132
|
kind: Literal["array"]
|
|
133
133
|
element_type: "ConcreteClassicalType"
|
|
134
|
-
length:
|
|
134
|
+
length: Expression | None = None
|
|
135
135
|
|
|
136
136
|
@pydantic.model_validator(mode="before")
|
|
137
137
|
@classmethod
|
|
@@ -160,7 +160,7 @@ class ClassicalArray(ClassicalType):
|
|
|
160
160
|
return self.length.to_int_value()
|
|
161
161
|
|
|
162
162
|
def get_classical_proxy(self, handle: HandleBinding) -> ClassicalProxy:
|
|
163
|
-
length:
|
|
163
|
+
length: ExpressionValue | None
|
|
164
164
|
if self.length is None:
|
|
165
165
|
length = None
|
|
166
166
|
elif not self.length.is_evaluated():
|
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
from classiq.interface.enum_utils import StrEnum
|
|
2
|
-
from classiq.interface.exceptions import ClassiqInternalExpansionError
|
|
3
2
|
|
|
4
3
|
|
|
5
4
|
class TypeModifier(StrEnum):
|
|
6
5
|
Const = "const"
|
|
7
|
-
Permutable = "permutable"
|
|
8
6
|
Mutable = "mutable"
|
|
9
7
|
Inferred = "inferred"
|
|
10
|
-
|
|
11
|
-
@staticmethod
|
|
12
|
-
def and_(first: "TypeModifier", second: "TypeModifier") -> "TypeModifier":
|
|
13
|
-
if second is TypeModifier.Inferred:
|
|
14
|
-
raise ClassiqInternalExpansionError
|
|
15
|
-
if first is TypeModifier.Mutable or second is TypeModifier.Mutable:
|
|
16
|
-
return TypeModifier.Mutable
|
|
17
|
-
elif first is TypeModifier.Permutable or second is TypeModifier.Permutable:
|
|
18
|
-
return TypeModifier.Permutable
|
|
19
|
-
else:
|
|
20
|
-
if first is not TypeModifier.Const and second is not TypeModifier.Const:
|
|
21
|
-
raise ClassiqInternalExpansionError("Unexpected type modifiers")
|
|
22
|
-
return TypeModifier.Const
|
|
@@ -35,8 +35,8 @@ if TYPE_CHECKING:
|
|
|
35
35
|
class TypeName(ClassicalType, QuantumType):
|
|
36
36
|
kind: Literal["struct_instance"]
|
|
37
37
|
name: str = pydantic.Field(description="The type name of the instance")
|
|
38
|
-
_assigned_fields:
|
|
39
|
-
|
|
38
|
+
_assigned_fields: Mapping[str, "ConcreteQuantumType"] | None = pydantic.PrivateAttr(
|
|
39
|
+
default=None
|
|
40
40
|
)
|
|
41
41
|
_classical_struct_decl: Optional["StructDeclaration"] = pydantic.PrivateAttr(
|
|
42
42
|
default=None
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import re
|
|
3
|
-
from typing import Literal,
|
|
3
|
+
from typing import Literal, TypeAlias
|
|
4
4
|
from uuid import UUID
|
|
5
5
|
|
|
6
6
|
import pydantic
|
|
7
7
|
from pydantic import ConfigDict, Field
|
|
8
|
-
from typing_extensions import TypeAlias
|
|
9
8
|
|
|
10
9
|
from classiq.interface.debug_info.back_ref_util import is_allocate_or_free_by_backref
|
|
11
10
|
from classiq.interface.enum_utils import StrEnum
|
|
@@ -87,12 +86,12 @@ class GeneratedFunction(pydantic.BaseModel):
|
|
|
87
86
|
name: str
|
|
88
87
|
control_states: list[ControlState]
|
|
89
88
|
registers: list[GeneratedRegister] = list()
|
|
90
|
-
depth:
|
|
91
|
-
width:
|
|
89
|
+
depth: int | None = pydantic.Field(default=None)
|
|
90
|
+
width: int | None = pydantic.Field(default=None)
|
|
92
91
|
dangling_inputs: dict[str, GeneratedRegister] = dict()
|
|
93
92
|
dangling_outputs: dict[str, GeneratedRegister] = dict()
|
|
94
93
|
|
|
95
|
-
def __getitem__(self, key:
|
|
94
|
+
def __getitem__(self, key: int | str) -> GeneratedRegister:
|
|
96
95
|
if isinstance(key, int):
|
|
97
96
|
return self.registers[key]
|
|
98
97
|
if isinstance(key, str):
|
|
@@ -101,7 +100,7 @@ class GeneratedFunction(pydantic.BaseModel):
|
|
|
101
100
|
return register
|
|
102
101
|
raise KeyError(key)
|
|
103
102
|
|
|
104
|
-
def get(self, key:
|
|
103
|
+
def get(self, key: int | str) -> GeneratedRegister | None:
|
|
105
104
|
try:
|
|
106
105
|
return self.__getitem__(key)
|
|
107
106
|
except KeyError:
|
|
@@ -119,7 +118,7 @@ class GeneratedCircuitData(pydantic.BaseModel):
|
|
|
119
118
|
width: int
|
|
120
119
|
circuit_parameters: list[ParameterName] = pydantic.Field(default_factory=list)
|
|
121
120
|
qubit_mapping: QubitMapping = pydantic.Field(default_factory=QubitMapping)
|
|
122
|
-
execution_data:
|
|
121
|
+
execution_data: ExecutionData | None = pydantic.Field(default=None)
|
|
123
122
|
|
|
124
123
|
@classmethod
|
|
125
124
|
def from_empty_logic_flow(cls) -> "GeneratedCircuitData":
|
|
@@ -176,21 +175,20 @@ STATEMENTS_NAME: dict[str, StatementType] = {
|
|
|
176
175
|
|
|
177
176
|
|
|
178
177
|
class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
179
|
-
generated_function:
|
|
178
|
+
generated_function: GeneratedFunction | None = Field(default=None)
|
|
180
179
|
children: list["FunctionDebugInfoInterface"]
|
|
181
180
|
relative_qubits: tuple[int, ...]
|
|
182
|
-
absolute_qubits:
|
|
183
|
-
control_variable:
|
|
184
|
-
is_basis_gate:
|
|
181
|
+
absolute_qubits: tuple[int, ...] | None = Field(default=None)
|
|
182
|
+
control_variable: str | None = Field(default=None)
|
|
183
|
+
is_basis_gate: bool | None = Field(default=None)
|
|
185
184
|
is_inverse: bool = Field(default=False)
|
|
185
|
+
is_daggered: bool = Field(default=False)
|
|
186
186
|
is_unitary: bool = Field(default=True, exclude=True)
|
|
187
|
-
uuid:
|
|
187
|
+
uuid: UUID | None = Field(default=None, exclude=True)
|
|
188
188
|
port_to_passed_variable_map: dict[str, str] = Field(default={})
|
|
189
189
|
back_refs: StatementBlock = Field(default_factory=list)
|
|
190
190
|
|
|
191
191
|
model_config = ConfigDict(extra="allow")
|
|
192
|
-
# Temporary field to store the override debug info for parallel old/new visualization
|
|
193
|
-
override_debug_info: Optional["FunctionDebugInfoInterface"] = None
|
|
194
192
|
|
|
195
193
|
@property
|
|
196
194
|
def is_allocate_or_free(self) -> bool:
|
|
@@ -229,7 +227,7 @@ class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
|
229
227
|
return f"{name}{suffix}"
|
|
230
228
|
|
|
231
229
|
@property
|
|
232
|
-
def first_back_ref(self) ->
|
|
230
|
+
def first_back_ref(self) -> ConcreteQuantumStatement | None:
|
|
233
231
|
return self.back_refs[0] if self.back_refs else None
|
|
234
232
|
|
|
235
233
|
@property
|
|
@@ -318,9 +316,6 @@ class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
|
318
316
|
)
|
|
319
317
|
|
|
320
318
|
def inverse(self) -> "FunctionDebugInfoInterface":
|
|
321
|
-
if self.override_debug_info is not None:
|
|
322
|
-
self.override_debug_info = self.override_debug_info.inverse()
|
|
323
|
-
return self
|
|
324
319
|
inverse_generated_function = (
|
|
325
320
|
self.generated_function.model_copy(
|
|
326
321
|
update=dict(registers=self._inverse_registers)
|
|
@@ -332,6 +327,7 @@ class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
|
332
327
|
return self.model_copy(
|
|
333
328
|
update=dict(
|
|
334
329
|
is_inverse=not self.is_inverse,
|
|
330
|
+
is_daggered=not self.is_daggered,
|
|
335
331
|
children=inverted_children,
|
|
336
332
|
generated_function=inverse_generated_function,
|
|
337
333
|
)
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
1
|
import pydantic
|
|
4
2
|
|
|
5
3
|
from classiq.interface.chemistry import operator
|
|
@@ -16,10 +14,10 @@ class ExponentiationOptimization(StrEnum):
|
|
|
16
14
|
|
|
17
15
|
|
|
18
16
|
class ExponentiationConstraints(pydantic.BaseModel):
|
|
19
|
-
max_depth:
|
|
17
|
+
max_depth: pydantic.PositiveInt | None = pydantic.Field(
|
|
20
18
|
default=None, description="Maximum depth of the exponentiation circuit."
|
|
21
19
|
)
|
|
22
|
-
max_error:
|
|
20
|
+
max_error: pydantic.PositiveFloat | None = pydantic.Field(
|
|
23
21
|
default=None,
|
|
24
22
|
description="Maximum approximation error of the exponentiation circuit.",
|
|
25
23
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import itertools
|
|
2
2
|
from collections import defaultdict
|
|
3
3
|
from collections.abc import MutableSet
|
|
4
|
-
from typing import Any
|
|
4
|
+
from typing import Any
|
|
5
5
|
|
|
6
6
|
import pydantic
|
|
7
7
|
from typing_extensions import Self
|
|
@@ -50,7 +50,7 @@ class HardwareData(pydantic.BaseModel):
|
|
|
50
50
|
f"If no connectivity map is given or the connectivity map is symmetric - {sorted(DEFAULT_BASIS_GATES)}. "
|
|
51
51
|
f"If a non-symmetric connectivity map is given - {sorted(DEFAULT_ROUTING_BASIS_GATES)}. ",
|
|
52
52
|
)
|
|
53
|
-
connectivity_map:
|
|
53
|
+
connectivity_map: ConnectivityMap | None = pydantic.Field(
|
|
54
54
|
default=None,
|
|
55
55
|
description="Qubit connectivity map, in the form [ [q0, q1], [q1, q2],...]. "
|
|
56
56
|
"If none given, assume the hardware is fully connected",
|
|
@@ -65,8 +65,8 @@ class HardwareData(pydantic.BaseModel):
|
|
|
65
65
|
@pydantic.field_validator("connectivity_map")
|
|
66
66
|
@classmethod
|
|
67
67
|
def _validate_connectivity_map(
|
|
68
|
-
cls, connectivity_map:
|
|
69
|
-
) ->
|
|
68
|
+
cls, connectivity_map: ConnectivityMap | None
|
|
69
|
+
) -> ConnectivityMap | None:
|
|
70
70
|
if connectivity_map is None:
|
|
71
71
|
return connectivity_map
|
|
72
72
|
if not connectivity_map:
|
|
@@ -128,7 +128,7 @@ class CustomHardwareSettings(HardwareData):
|
|
|
128
128
|
|
|
129
129
|
"""
|
|
130
130
|
|
|
131
|
-
_width:
|
|
131
|
+
_width: int | None = pydantic.PrivateAttr(default=None)
|
|
132
132
|
|
|
133
133
|
@pydantic.field_validator("basis_gates", mode="after")
|
|
134
134
|
@classmethod
|
|
@@ -144,14 +144,14 @@ class CustomHardwareSettings(HardwareData):
|
|
|
144
144
|
|
|
145
145
|
def __init__(self, **kwargs: Any) -> None:
|
|
146
146
|
super().__init__(**kwargs)
|
|
147
|
-
self._width:
|
|
147
|
+
self._width: int | None = (
|
|
148
148
|
len(set(itertools.chain.from_iterable(self.connectivity_map)))
|
|
149
149
|
if self.connectivity_map
|
|
150
150
|
else None
|
|
151
151
|
)
|
|
152
152
|
|
|
153
153
|
@property
|
|
154
|
-
def width(self) ->
|
|
154
|
+
def width(self) -> int | None:
|
|
155
155
|
return self._width
|
|
156
156
|
|
|
157
157
|
|
|
@@ -221,4 +221,4 @@ class SynthesisHardwareData(HardwareData):
|
|
|
221
221
|
Defaults to `None`.
|
|
222
222
|
"""
|
|
223
223
|
|
|
224
|
-
backend_data:
|
|
224
|
+
backend_data: BackendPreferences | None = pydantic.Field(default=None)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import itertools
|
|
2
|
-
from typing import TYPE_CHECKING,
|
|
2
|
+
from typing import TYPE_CHECKING, Union
|
|
3
3
|
|
|
4
4
|
import pydantic
|
|
5
5
|
from pydantic_core.core_schema import ValidationInfo
|
|
@@ -42,7 +42,7 @@ class HardwareEfficientAnsatz(function_params.FunctionParams):
|
|
|
42
42
|
"If none specified - use connectivity map from the model hardware settings. "
|
|
43
43
|
"If none specified as well, all qubit pairs will be connected.",
|
|
44
44
|
)
|
|
45
|
-
num_qubits: pydantic.PositiveInt = pydantic.Field(
|
|
45
|
+
num_qubits: pydantic.PositiveInt = pydantic.Field(
|
|
46
46
|
default=None,
|
|
47
47
|
description="Number of qubits in the ansatz.",
|
|
48
48
|
validate_default=True,
|
|
@@ -51,11 +51,11 @@ class HardwareEfficientAnsatz(function_params.FunctionParams):
|
|
|
51
51
|
default=1, description="Number of layers in the Ansatz"
|
|
52
52
|
)
|
|
53
53
|
|
|
54
|
-
one_qubit_gates:
|
|
54
|
+
one_qubit_gates: str | list[str] = pydantic.Field(
|
|
55
55
|
default=["x", "ry"],
|
|
56
56
|
description='List of gates for the one qubit gates layer, e.g. ["x", "ry"]',
|
|
57
57
|
)
|
|
58
|
-
two_qubit_gates:
|
|
58
|
+
two_qubit_gates: str | list[str] = pydantic.Field(
|
|
59
59
|
default=["cx"],
|
|
60
60
|
description='List of gates for the two qubit gates entangling layer, e.g. ["cx", "cry"]',
|
|
61
61
|
)
|
|
@@ -67,7 +67,7 @@ class HardwareEfficientAnsatz(function_params.FunctionParams):
|
|
|
67
67
|
@pydantic.field_validator("num_qubits", mode="before")
|
|
68
68
|
@classmethod
|
|
69
69
|
def validate_num_qubits(
|
|
70
|
-
cls, num_qubits:
|
|
70
|
+
cls, num_qubits: pydantic.PositiveInt | None, info: ValidationInfo
|
|
71
71
|
) -> pydantic.PositiveInt:
|
|
72
72
|
connectivity_map = info.data.get("connectivity_map")
|
|
73
73
|
conn_map_is_not_list = (
|
|
@@ -107,8 +107,8 @@ class HardwareEfficientAnsatz(function_params.FunctionParams):
|
|
|
107
107
|
@pydantic.field_validator("one_qubit_gates")
|
|
108
108
|
@classmethod
|
|
109
109
|
def validate_one_qubit_gates(
|
|
110
|
-
cls, one_qubit_gates:
|
|
111
|
-
) ->
|
|
110
|
+
cls, one_qubit_gates: str | list[str]
|
|
111
|
+
) -> str | list[str]:
|
|
112
112
|
one_qubit_gates_list = (
|
|
113
113
|
[one_qubit_gates] if isinstance(one_qubit_gates, str) else one_qubit_gates
|
|
114
114
|
)
|
|
@@ -120,8 +120,8 @@ class HardwareEfficientAnsatz(function_params.FunctionParams):
|
|
|
120
120
|
@pydantic.field_validator("two_qubit_gates")
|
|
121
121
|
@classmethod
|
|
122
122
|
def validate_two_qubit_gates(
|
|
123
|
-
cls, two_qubit_gates:
|
|
124
|
-
) ->
|
|
123
|
+
cls, two_qubit_gates: str | list[str]
|
|
124
|
+
) -> str | list[str]:
|
|
125
125
|
two_qubit_gates_list = (
|
|
126
126
|
[two_qubit_gates] if isinstance(two_qubit_gates, str) else two_qubit_gates
|
|
127
127
|
)
|