classiq 0.53.0__py3-none-any.whl → 0.54.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 +1 -3
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +2 -1
- classiq/_internals/__init__.py +0 -20
- classiq/_internals/api_wrapper.py +8 -8
- classiq/_internals/async_utils.py +1 -3
- classiq/_internals/authentication/auth0.py +5 -5
- classiq/_internals/authentication/device.py +5 -4
- classiq/_internals/authentication/password_manager.py +3 -3
- classiq/_internals/authentication/token_manager.py +3 -2
- classiq/_internals/client.py +10 -12
- classiq/_internals/config.py +2 -2
- classiq/_internals/jobs.py +7 -6
- classiq/_internals/type_validation.py +9 -9
- classiq/analyzer/__init__.py +1 -3
- classiq/analyzer/analyzer.py +8 -7
- classiq/analyzer/analyzer_utilities.py +8 -8
- classiq/analyzer/rb.py +11 -11
- classiq/applications/__init__.py +1 -3
- classiq/applications/chemistry/__init__.py +1 -3
- classiq/applications/chemistry/ansatz_parameters.py +4 -4
- classiq/applications/chemistry/chemistry_model_constructor.py +10 -9
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +26 -9
- classiq/applications/combinatorial_helpers/encoding_mapping.py +10 -10
- classiq/applications/combinatorial_helpers/encoding_utils.py +4 -4
- classiq/applications/combinatorial_helpers/memory.py +5 -7
- classiq/applications/combinatorial_helpers/optimization_model.py +43 -24
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +4 -6
- classiq/applications/combinatorial_helpers/pyomo_utils.py +95 -24
- classiq/applications/combinatorial_helpers/sympy_utils.py +2 -2
- classiq/applications/combinatorial_helpers/transformations/encoding.py +8 -8
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +5 -5
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +7 -9
- classiq/applications/combinatorial_helpers/transformations/penalty.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/slack_variables.py +1 -2
- classiq/applications/combinatorial_optimization/__init__.py +1 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -2
- classiq/applications/combinatorial_optimization/examples/__init__.py +1 -3
- classiq/applications/finance/__init__.py +1 -3
- classiq/applications/grover/__init__.py +1 -3
- classiq/applications/grover/grover_model_constructor.py +7 -9
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -6
- classiq/applications/qnn/__init__.py +1 -3
- classiq/applications/qnn/circuit_utils.py +5 -5
- classiq/applications/qnn/datasets/__init__.py +1 -3
- classiq/applications/qnn/datasets/dataset_base_classes.py +5 -4
- classiq/applications/qnn/datasets/dataset_parity.py +2 -2
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +2 -1
- classiq/applications/qnn/qlayer.py +3 -3
- classiq/applications/qnn/torch_utils.py +2 -2
- classiq/applications/qnn/types.py +5 -5
- classiq/applications/qsvm/qsvm.py +1 -3
- classiq/applications/qsvm/qsvm_data_generation.py +3 -3
- classiq/applications/qsvm/qsvm_model_constructor.py +5 -5
- classiq/execution/__init__.py +1 -3
- classiq/execution/all_hardware_devices.py +1 -3
- classiq/execution/execution_session.py +16 -16
- classiq/execution/jobs.py +4 -4
- classiq/execution/qaoa.py +3 -3
- classiq/execution/qnn.py +3 -3
- classiq/executor.py +3 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +9 -10
- classiq/interface/analyzer/cytoscape_graph.py +5 -5
- classiq/interface/analyzer/result.py +17 -17
- classiq/interface/applications/qsvm.py +6 -10
- classiq/interface/backend/backend_preferences.py +4 -3
- classiq/interface/backend/ionq/ionq_quantum_program.py +4 -5
- classiq/interface/backend/pydantic_backend.py +1 -2
- classiq/interface/chemistry/fermionic_operator.py +5 -5
- classiq/interface/chemistry/ground_state_problem.py +7 -8
- classiq/interface/chemistry/molecule.py +4 -4
- classiq/interface/chemistry/operator.py +11 -13
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +1 -3
- classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -4
- classiq/interface/combinatorial_optimization/examples/knapsack.py +3 -3
- classiq/interface/combinatorial_optimization/examples/mht.py +2 -3
- classiq/interface/combinatorial_optimization/examples/portfolio_variations.py +2 -2
- classiq/interface/combinatorial_optimization/examples/set_cover.py +1 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +5 -7
- classiq/interface/combinatorial_optimization/optimization_problem.py +2 -2
- classiq/interface/combinatorial_optimization/result.py +1 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +8 -6
- classiq/interface/execution/jobs.py +2 -2
- classiq/interface/execution/primitives.py +3 -3
- classiq/interface/executor/aws_execution_cost.py +4 -4
- classiq/interface/executor/execution_request.py +2 -3
- classiq/interface/executor/execution_result.py +3 -3
- classiq/interface/executor/iqae_result.py +3 -5
- classiq/interface/executor/optimizer_preferences.py +2 -2
- classiq/interface/executor/quantum_code.py +6 -6
- classiq/interface/executor/register_initialization.py +2 -4
- classiq/interface/executor/result.py +23 -27
- classiq/interface/executor/vqe_result.py +8 -8
- classiq/interface/finance/function_input.py +2 -2
- classiq/interface/finance/gaussian_model_input.py +5 -5
- classiq/interface/finance/log_normal_model_input.py +2 -2
- classiq/interface/finance/model_input.py +1 -2
- classiq/interface/generator/adjacency.py +1 -3
- classiq/interface/generator/ansatz_library.py +4 -4
- classiq/interface/generator/application_apis/finance_declarations.py +1 -1
- classiq/interface/generator/arith/argument_utils.py +3 -3
- classiq/interface/generator/arith/arithmetic.py +7 -7
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +5 -5
- classiq/interface/generator/arith/arithmetic_expression_abc.py +11 -11
- classiq/interface/generator/arith/arithmetic_expression_parser.py +8 -7
- classiq/interface/generator/arith/arithmetic_expression_validator.py +8 -8
- classiq/interface/generator/arith/arithmetic_operations.py +4 -3
- classiq/interface/generator/arith/arithmetic_param_getters.py +6 -6
- classiq/interface/generator/arith/arithmetic_result_builder.py +9 -9
- classiq/interface/generator/arith/ast_node_rewrite.py +2 -1
- classiq/interface/generator/arith/binary_ops.py +10 -13
- classiq/interface/generator/arith/extremum_operations.py +3 -2
- classiq/interface/generator/arith/logical_ops.py +7 -6
- classiq/interface/generator/arith/number_utils.py +4 -4
- classiq/interface/generator/arith/register_user_input.py +4 -4
- classiq/interface/generator/arith/unary_ops.py +2 -1
- classiq/interface/generator/builtin_api_builder.py +2 -1
- classiq/interface/generator/circuit_code/circuit_code.py +4 -4
- classiq/interface/generator/circuit_code/types_and_constants.py +3 -5
- classiq/interface/generator/complex_type.py +1 -2
- classiq/interface/generator/control_state.py +2 -2
- classiq/interface/generator/custom_ansatz.py +1 -3
- classiq/interface/generator/distance.py +3 -5
- classiq/interface/generator/excitations.py +3 -2
- classiq/interface/generator/expressions/enums/finance_functions.py +1 -3
- classiq/interface/generator/expressions/evaluated_expression.py +4 -3
- classiq/interface/generator/expressions/expression.py +4 -5
- classiq/interface/generator/expressions/expression_constants.py +4 -4
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_sized_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_struct_instance.py +2 -1
- classiq/interface/generator/expressions/sympy_supported_expressions.py +11 -13
- classiq/interface/generator/finance.py +2 -2
- classiq/interface/generator/function_param_library.py +6 -6
- classiq/interface/generator/function_params.py +13 -19
- classiq/interface/generator/functions/classical_function_declaration.py +4 -3
- classiq/interface/generator/functions/classical_type.py +13 -13
- classiq/interface/generator/functions/concrete_types.py +1 -2
- classiq/interface/generator/functions/function_declaration.py +1 -1
- classiq/interface/generator/functions/qmod_python_interface.py +2 -1
- classiq/interface/generator/functions/type_name.py +3 -2
- classiq/interface/generator/generated_circuit_data.py +34 -22
- classiq/interface/generator/grover_diffuser.py +7 -7
- classiq/interface/generator/grover_operator.py +2 -2
- classiq/interface/generator/hardware/hardware_data.py +7 -6
- classiq/interface/generator/hardware_efficient_ansatz.py +8 -8
- classiq/interface/generator/identity.py +5 -6
- classiq/interface/generator/linear_pauli_rotations.py +6 -6
- classiq/interface/generator/mcu.py +2 -2
- classiq/interface/generator/mcx.py +6 -6
- classiq/interface/generator/model/__init__.py +1 -3
- classiq/interface/generator/model/constraints.py +2 -2
- classiq/interface/generator/model/model.py +5 -6
- classiq/interface/generator/model/preferences/preferences.py +7 -6
- classiq/interface/generator/model/quantum_register.py +6 -11
- classiq/interface/generator/oracles/arithmetic_oracle.py +1 -2
- classiq/interface/generator/oracles/custom_oracle.py +2 -2
- classiq/interface/generator/oracles/oracle_abc.py +6 -5
- classiq/interface/generator/partitioned_register.py +6 -5
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +8 -7
- classiq/interface/generator/qpe.py +4 -4
- classiq/interface/generator/qsvm.py +3 -3
- classiq/interface/generator/quantum_function_call.py +24 -29
- classiq/interface/generator/quantum_program.py +9 -9
- classiq/interface/generator/register_role.py +2 -4
- classiq/interface/generator/slice_parsing_utils.py +4 -3
- classiq/interface/generator/standard_gates/standard_gates.py +3 -3
- classiq/interface/generator/state_preparation/bell_state_preparation.py +3 -3
- classiq/interface/generator/state_preparation/distributions.py +6 -5
- classiq/interface/generator/state_preparation/metrics.py +2 -4
- classiq/interface/generator/state_preparation/state_preparation.py +4 -4
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +3 -3
- classiq/interface/generator/transpiler_basis_gates.py +2 -2
- classiq/interface/generator/types/enum_declaration.py +2 -3
- classiq/interface/generator/types/qstruct_declaration.py +2 -1
- classiq/interface/generator/types/struct_declaration.py +3 -2
- classiq/interface/generator/ucc.py +2 -1
- classiq/interface/generator/unitary_gate.py +2 -2
- classiq/interface/generator/user_defined_function_params.py +1 -1
- classiq/interface/generator/validations/flow_graph.py +6 -5
- classiq/interface/generator/validations/validator_functions.py +3 -2
- classiq/interface/generator/visitor.py +9 -14
- classiq/interface/hardware.py +5 -6
- classiq/interface/helpers/custom_encoders.py +2 -2
- classiq/interface/helpers/custom_pydantic_types.py +8 -9
- classiq/interface/helpers/hashable_mixin.py +3 -2
- classiq/interface/helpers/hashable_pydantic_base_model.py +2 -1
- classiq/interface/helpers/pydantic_model_helpers.py +4 -3
- classiq/interface/helpers/validation_helpers.py +2 -2
- classiq/interface/ide/ide_data.py +11 -15
- classiq/interface/ide/visual_model.py +20 -22
- classiq/interface/jobs.py +2 -2
- classiq/interface/model/bind_operation.py +5 -4
- classiq/interface/model/classical_parameter_declaration.py +2 -2
- classiq/interface/model/handle_binding.py +3 -2
- classiq/interface/model/inplace_binary_operation.py +2 -1
- classiq/interface/model/model.py +12 -11
- classiq/interface/model/port_declaration.py +2 -2
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +3 -2
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +3 -2
- classiq/interface/model/quantum_expressions/quantum_expression.py +8 -7
- classiq/interface/model/quantum_function_call.py +9 -14
- classiq/interface/model/quantum_function_declaration.py +10 -12
- classiq/interface/model/quantum_lambda_function.py +3 -16
- classiq/interface/model/quantum_statement.py +4 -3
- classiq/interface/model/quantum_type.py +5 -5
- classiq/interface/model/statement_block.py +2 -3
- classiq/interface/model/validation_handle.py +5 -4
- classiq/interface/server/global_versions.py +3 -3
- classiq/model_expansions/atomic_expression_functions_defs.py +3 -2
- classiq/model_expansions/call_to_model_converter.py +190 -0
- classiq/model_expansions/capturing/captured_var_manager.py +4 -6
- classiq/model_expansions/capturing/propagated_var_stack.py +7 -7
- classiq/model_expansions/closure.py +17 -9
- classiq/model_expansions/evaluators/arg_type_match.py +3 -2
- classiq/model_expansions/evaluators/argument_types.py +3 -3
- classiq/model_expansions/evaluators/control.py +3 -3
- classiq/model_expansions/evaluators/parameter_types.py +7 -7
- classiq/model_expansions/evaluators/quantum_type_utils.py +2 -1
- classiq/model_expansions/evaluators/type_type_match.py +1 -1
- classiq/model_expansions/expression_evaluator.py +10 -9
- classiq/model_expansions/expression_renamer.py +6 -6
- classiq/model_expansions/function_builder.py +19 -12
- classiq/model_expansions/generative_functions.py +3 -2
- classiq/model_expansions/interpreter.py +31 -19
- classiq/model_expansions/model_tables.py +14 -14
- classiq/model_expansions/quantum_operations/bind.py +2 -4
- classiq/model_expansions/quantum_operations/classicalif.py +1 -1
- classiq/model_expansions/quantum_operations/control.py +2 -4
- classiq/model_expansions/quantum_operations/emitter.py +10 -13
- classiq/model_expansions/quantum_operations/expression_operation.py +23 -16
- classiq/model_expansions/quantum_operations/inplace_binary_operation.py +160 -35
- classiq/model_expansions/quantum_operations/phase.py +6 -6
- classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +25 -5
- classiq/model_expansions/quantum_operations/quantum_function_call.py +41 -2
- classiq/model_expansions/quantum_operations/repeat.py +1 -3
- classiq/model_expansions/scope.py +11 -10
- classiq/model_expansions/scope_initialization.py +6 -5
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +6 -6
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +2 -2
- classiq/model_expansions/visitors/variable_references.py +5 -4
- classiq/qmod/builtins/classical_execution_primitives.py +9 -9
- classiq/qmod/builtins/functions/__init__.py +72 -55
- classiq/qmod/builtins/functions/amplitude_estimation.py +4 -1
- classiq/qmod/builtins/functions/arithmetic.py +14 -1
- classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +86 -6
- classiq/qmod/builtins/functions/grover.py +41 -45
- classiq/qmod/builtins/functions/hea.py +60 -4
- classiq/qmod/builtins/functions/linear_pauli_rotation.py +26 -4
- classiq/qmod/builtins/functions/modular_exponentiation.py +90 -29
- classiq/qmod/builtins/functions/operators.py +1 -1
- classiq/qmod/builtins/functions/qaoa_penalty.py +14 -5
- classiq/qmod/builtins/functions/qft_functions.py +57 -0
- classiq/qmod/builtins/functions/qpe.py +20 -4
- classiq/qmod/builtins/functions/qsvt.py +49 -4
- classiq/qmod/builtins/functions/standard_gates.py +4 -4
- classiq/qmod/builtins/functions/state_preparation.py +92 -10
- classiq/qmod/builtins/functions/swap_test.py +7 -1
- classiq/qmod/builtins/functions/utility_functions.py +43 -0
- classiq/qmod/builtins/functions/variational.py +18 -2
- classiq/qmod/builtins/operations.py +4 -5
- classiq/qmod/cfunc.py +2 -2
- classiq/qmod/classical_function.py +3 -7
- classiq/qmod/create_model_function.py +7 -6
- classiq/qmod/declaration_inferrer.py +7 -10
- classiq/qmod/expression_query.py +3 -3
- classiq/qmod/generative.py +2 -1
- classiq/qmod/model_state_container.py +5 -7
- classiq/qmod/native/__init__.py +1 -3
- classiq/qmod/native/expression_to_qmod.py +9 -8
- classiq/qmod/native/pretty_printer.py +6 -5
- classiq/qmod/pretty_print/__init__.py +1 -3
- classiq/qmod/pretty_print/expression_to_python.py +13 -12
- classiq/qmod/pretty_print/pretty_printer.py +13 -12
- classiq/qmod/python_classical_type.py +8 -4
- classiq/qmod/qfunc.py +4 -4
- classiq/qmod/qmod_variable.py +11 -10
- classiq/qmod/quantum_expandable.py +12 -15
- classiq/qmod/quantum_function.py +10 -3
- classiq/qmod/semantics/annotation.py +1 -1
- classiq/qmod/semantics/error_manager.py +8 -7
- classiq/qmod/semantics/static_semantics_visitor.py +19 -24
- classiq/qmod/semantics/validation/constants_validation.py +1 -1
- classiq/qmod/semantics/validation/func_call_validation.py +2 -2
- classiq/qmod/semantics/validation/main_validation.py +33 -0
- classiq/qmod/semantics/validation/types_validation.py +2 -1
- classiq/qmod/symbolic.py +5 -8
- classiq/qmod/symbolic_type.py +2 -2
- {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/METADATA +1 -1
- {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/RECORD +295 -292
- classiq/qmod/builtins/functions/qft.py +0 -23
- {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/WHEEL +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
import json
|
2
|
-
from typing import Any, Callable,
|
2
|
+
from typing import Any, Callable, Optional, Union, cast
|
3
3
|
|
4
4
|
import numpy as np
|
5
5
|
|
@@ -28,12 +28,12 @@ from classiq.qmod.builtins.classical_execution_primitives import (
|
|
28
28
|
)
|
29
29
|
from classiq.synthesis import SerializedQuantumProgram
|
30
30
|
|
31
|
-
Hamiltonian = Union[
|
31
|
+
Hamiltonian = Union[list[QmodPyStruct], list[PauliTerm]]
|
32
32
|
Program = Union[SerializedQuantumProgram, QuantumProgram]
|
33
|
-
ParsedExecutionParams =
|
34
|
-
ExecutionParameters = Optional[Union[ExecutionParams,
|
33
|
+
ParsedExecutionParams = dict[str, Union[float, int]]
|
34
|
+
ExecutionParameters = Optional[Union[ExecutionParams, list[ExecutionParams]]]
|
35
35
|
ParsedExecutionParameters = Optional[
|
36
|
-
Union[ParsedExecutionParams,
|
36
|
+
Union[ParsedExecutionParams, list[ParsedExecutionParams]]
|
37
37
|
]
|
38
38
|
|
39
39
|
|
@@ -55,11 +55,11 @@ def _deserialize_program(program: Program) -> QuantumProgram:
|
|
55
55
|
)
|
56
56
|
|
57
57
|
|
58
|
-
def hamiltonian_to_pauli_terms(hamiltonian: Hamiltonian) ->
|
58
|
+
def hamiltonian_to_pauli_terms(hamiltonian: Hamiltonian) -> list[PauliTerm]:
|
59
59
|
if isinstance(hamiltonian[0], PauliTerm):
|
60
|
-
return cast(
|
60
|
+
return cast(list[PauliTerm], hamiltonian)
|
61
61
|
else:
|
62
|
-
return _pauli_dict_to_pauli_terms(cast(
|
62
|
+
return _pauli_dict_to_pauli_terms(cast(list[QmodPyStruct], hamiltonian))
|
63
63
|
|
64
64
|
|
65
65
|
def to_hamiltonian_str(hamiltonian: Hamiltonian) -> str:
|
@@ -78,8 +78,8 @@ def _hamiltonian_to_pauli_operator(hamiltonian: Hamiltonian) -> PauliOperator:
|
|
78
78
|
|
79
79
|
|
80
80
|
def serialize(
|
81
|
-
item: Union[float, int,
|
82
|
-
) -> Union[str,
|
81
|
+
item: Union[float, int, tuple[int, ...], tuple[float, ...]]
|
82
|
+
) -> Union[str, list]:
|
83
83
|
if isinstance(item, tuple):
|
84
84
|
return list(item)
|
85
85
|
return str(item)
|
@@ -126,7 +126,7 @@ def create_sample_execution_code(operation: str, **kwargs: Any) -> str:
|
|
126
126
|
return f"\nresult = {operation}({parameters})" + SAVE_RESULT
|
127
127
|
|
128
128
|
|
129
|
-
operation_handlers:
|
129
|
+
operation_handlers: dict[str, Callable[[str], str]] = {
|
130
130
|
"estimate": create_estimate_execution_code,
|
131
131
|
"batch_estimate": create_estimate_execution_code,
|
132
132
|
"sample": create_sample_execution_code,
|
@@ -218,7 +218,7 @@ class ExecutionSession:
|
|
218
218
|
)
|
219
219
|
return execute(SerializedQuantumProgram(self.qprog))
|
220
220
|
|
221
|
-
def batch_sample(self, parameters:
|
221
|
+
def batch_sample(self, parameters: list[ExecutionParams]) -> list[ExecutionDetails]:
|
222
222
|
"""
|
223
223
|
Samples the quantum program multiple times with the given parameters for each iteration. The number of samples is determined by the length of the parameters list.
|
224
224
|
|
@@ -231,7 +231,7 @@ class ExecutionSession:
|
|
231
231
|
job = self.submit_batch_sample(parameters=parameters)
|
232
232
|
return job.get_batch_sample_result()
|
233
233
|
|
234
|
-
def submit_batch_sample(self, parameters:
|
234
|
+
def submit_batch_sample(self, parameters: list[ExecutionParams]) -> ExecutionJob:
|
235
235
|
"""
|
236
236
|
Initiates an execution job with the `batch_sample` primitive.
|
237
237
|
|
@@ -300,8 +300,8 @@ class ExecutionSession:
|
|
300
300
|
return execute(SerializedQuantumProgram(self.qprog))
|
301
301
|
|
302
302
|
def batch_estimate(
|
303
|
-
self, hamiltonian: Hamiltonian, parameters:
|
304
|
-
) ->
|
303
|
+
self, hamiltonian: Hamiltonian, parameters: list[ExecutionParams]
|
304
|
+
) -> list[EstimationResult]:
|
305
305
|
"""
|
306
306
|
Estimates the expectation value of the given Hamiltonian multiple times using the quantum program, with the given parameters for each iteration. The number of estimations is determined by the length of the parameters list.
|
307
307
|
|
@@ -316,7 +316,7 @@ class ExecutionSession:
|
|
316
316
|
return job.get_batch_estimate_result()
|
317
317
|
|
318
318
|
def submit_batch_estimate(
|
319
|
-
self, hamiltonian: Hamiltonian, parameters:
|
319
|
+
self, hamiltonian: Hamiltonian, parameters: list[ExecutionParams]
|
320
320
|
) -> ExecutionJob:
|
321
321
|
"""
|
322
322
|
Initiates an execution job with the `batch_estimate` primitive.
|
classiq/execution/jobs.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import webbrowser
|
2
2
|
from datetime import datetime
|
3
|
-
from typing import Any,
|
3
|
+
from typing import Any, Optional, Union
|
4
4
|
from urllib.parse import urljoin
|
5
5
|
|
6
6
|
from classiq.interface.exceptions import (
|
@@ -150,7 +150,7 @@ class ExecutionJob:
|
|
150
150
|
return result.details[0]
|
151
151
|
raise ClassiqExecutionResultError("sample")
|
152
152
|
|
153
|
-
def get_batch_sample_result(self) ->
|
153
|
+
def get_batch_sample_result(self) -> list[ExecutionDetails]:
|
154
154
|
"""
|
155
155
|
Returns the job's result as a single batch_sample result after validation. If the result is not yet available, waits for it.
|
156
156
|
|
@@ -195,7 +195,7 @@ class ExecutionJob:
|
|
195
195
|
return result.results[0]
|
196
196
|
raise ClassiqExecutionResultError("estimate")
|
197
197
|
|
198
|
-
def get_batch_estimate_result(self) ->
|
198
|
+
def get_batch_estimate_result(self) -> list[EstimationResult]:
|
199
199
|
"""
|
200
200
|
Returns the job's result as a single batch_estimate result after validation. If the result is not yet available, waits for it.
|
201
201
|
|
@@ -271,7 +271,7 @@ class ExecutionJob:
|
|
271
271
|
|
272
272
|
async def get_execution_jobs_async(
|
273
273
|
offset: int = 0, limit: int = 50
|
274
|
-
) ->
|
274
|
+
) -> list[ExecutionJob]:
|
275
275
|
result = await ApiWrapper().call_query_execution_jobs(offset=offset, limit=limit)
|
276
276
|
return [ExecutionJob(details) for details in result.results]
|
277
277
|
|
classiq/execution/qaoa.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import math
|
2
|
-
from typing import Callable, Optional
|
2
|
+
from typing import Callable, Optional
|
3
3
|
|
4
4
|
import numpy as np
|
5
5
|
import scipy
|
@@ -25,12 +25,12 @@ from classiq.synthesis import SerializedQuantumProgram, synthesize
|
|
25
25
|
|
26
26
|
|
27
27
|
def execute_qaoa(
|
28
|
-
problem_vars:
|
28
|
+
problem_vars: type[QVar],
|
29
29
|
cost_func: Callable,
|
30
30
|
num_layers: int,
|
31
31
|
maxiter: int,
|
32
32
|
execution_preferences: Optional[ExecutionPreferences] = None,
|
33
|
-
) ->
|
33
|
+
) -> tuple[SerializedModel, SerializedQuantumProgram, ExecutionDetails]:
|
34
34
|
"""
|
35
35
|
Implements a simple QAOA algorithm, including the creation and synthesis of the QAOA
|
36
36
|
ansatz and the classical optimization loop.
|
classiq/execution/qnn.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import functools
|
2
|
-
from typing import
|
2
|
+
from typing import Optional
|
3
3
|
|
4
4
|
import more_itertools
|
5
5
|
|
@@ -24,7 +24,7 @@ _MAX_ARGUMENTS_SIZE = 1024
|
|
24
24
|
|
25
25
|
def _execute_qnn_estimate(
|
26
26
|
session: ExecutionSession,
|
27
|
-
arguments:
|
27
|
+
arguments: list[Arguments],
|
28
28
|
observable: PauliOperator,
|
29
29
|
) -> ResultsCollection:
|
30
30
|
hamiltonian = pauli_operator_to_hamiltonian(observable.pauli_list)
|
@@ -42,7 +42,7 @@ def _execute_qnn_estimate(
|
|
42
42
|
|
43
43
|
def _execute_qnn_sample(
|
44
44
|
session: ExecutionSession,
|
45
|
-
arguments:
|
45
|
+
arguments: list[Arguments],
|
46
46
|
) -> ResultsCollection:
|
47
47
|
return [
|
48
48
|
TaggedExecutionDetails(
|
classiq/executor.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"""Executor module, implementing facilities for executing quantum programs using Classiq platform."""
|
2
2
|
|
3
|
-
from typing import
|
3
|
+
from typing import Union
|
4
4
|
|
5
5
|
from typing_extensions import TypeAlias
|
6
6
|
|
@@ -18,8 +18,8 @@ from classiq.execution.jobs import ExecutionJob
|
|
18
18
|
from classiq.synthesis import SerializedQuantumProgram
|
19
19
|
|
20
20
|
BatchExecutionResult: TypeAlias = Union[ExecutionDetails, BaseException]
|
21
|
-
ProgramAndResult: TypeAlias =
|
22
|
-
BackendPreferencesAndResult: TypeAlias =
|
21
|
+
ProgramAndResult: TypeAlias = tuple[QuantumCode, BatchExecutionResult]
|
22
|
+
BackendPreferencesAndResult: TypeAlias = tuple[
|
23
23
|
BackendPreferencesTypes, int, BatchExecutionResult
|
24
24
|
]
|
25
25
|
|
classiq/interface/_version.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Annotated, Optional
|
2
2
|
|
3
3
|
import numpy
|
4
4
|
import pydantic
|
5
5
|
from pydantic import ConfigDict, Field, StringConstraints
|
6
|
-
from typing_extensions import Annotated
|
7
6
|
|
8
7
|
from classiq.interface.backend.quantum_backend_providers import AnalyzerProviderVendor
|
9
8
|
from classiq.interface.chemistry.ground_state_problem import MoleculeProblem
|
@@ -30,17 +29,17 @@ class AnalysisParams(pydantic.BaseModel):
|
|
30
29
|
|
31
30
|
|
32
31
|
class HardwareListParams(pydantic.BaseModel):
|
33
|
-
devices: Optional[
|
32
|
+
devices: Optional[list[PydanticNonEmptyString]] = pydantic.Field(
|
34
33
|
default=None, description="Devices"
|
35
34
|
)
|
36
|
-
providers:
|
35
|
+
providers: list[Provider]
|
37
36
|
from_ide: bool = Field(default=False)
|
38
37
|
|
39
38
|
@pydantic.field_validator("providers")
|
40
39
|
@classmethod
|
41
40
|
def set_default_providers(
|
42
|
-
cls, providers: Optional[
|
43
|
-
) ->
|
41
|
+
cls, providers: Optional[list[AnalyzerProviderVendor]]
|
42
|
+
) -> list[AnalyzerProviderVendor]:
|
44
43
|
if providers is None:
|
45
44
|
providers = list(AnalyzerProviderVendor)
|
46
45
|
return providers
|
@@ -65,7 +64,7 @@ class GateNamsMapping(pydantic.BaseModel):
|
|
65
64
|
|
66
65
|
|
67
66
|
class LatexParams(AnalysisParams):
|
68
|
-
gate_names:
|
67
|
+
gate_names: list[GateNamsMapping] = pydantic.Field(
|
69
68
|
default=..., description="List of gate names as apper in the qasm"
|
70
69
|
)
|
71
70
|
|
@@ -96,12 +95,12 @@ class CircuitAnalysisHardwareParams(AnalysisParams):
|
|
96
95
|
|
97
96
|
class AnalysisRBParams(pydantic.BaseModel):
|
98
97
|
hardware: str
|
99
|
-
counts:
|
100
|
-
|
98
|
+
counts: list[
|
99
|
+
dict[
|
101
100
|
str, Annotated[int, Annotated[int, Field(strict=True, gt=0, le=MAX_COUNTS)]]
|
102
101
|
]
|
103
102
|
]
|
104
|
-
num_clifford:
|
103
|
+
num_clifford: list[
|
105
104
|
Annotated[int, Annotated[int, Field(strict=True, gt=0, le=MAX_NUM_CLIFFORD)]]
|
106
105
|
]
|
107
106
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any,
|
1
|
+
from typing import Any, Optional
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
@@ -25,7 +25,7 @@ class CytoScapeEdgeData(pydantic.BaseModel):
|
|
25
25
|
|
26
26
|
@pydantic.model_validator(mode="before")
|
27
27
|
@classmethod
|
28
|
-
def _validate_values(cls, values:
|
28
|
+
def _validate_values(cls, values: dict[str, Any]) -> dict[str, Any]:
|
29
29
|
values["source"] = str(values["source"]) or " "
|
30
30
|
values["target"] = str(values["target"]) or " "
|
31
31
|
return values
|
@@ -38,7 +38,7 @@ class CytoScapeEdge(pydantic.BaseModel):
|
|
38
38
|
|
39
39
|
|
40
40
|
class CytoScapeNode(pydantic.BaseModel):
|
41
|
-
data:
|
41
|
+
data: dict[str, Any] = pydantic.Field(
|
42
42
|
default=...,
|
43
43
|
description="Data of the Node, such as label, and color, can be of free form",
|
44
44
|
)
|
@@ -48,11 +48,11 @@ class CytoScapeNode(pydantic.BaseModel):
|
|
48
48
|
|
49
49
|
|
50
50
|
class CytoScapeGraph(pydantic.BaseModel):
|
51
|
-
nodes:
|
51
|
+
nodes: list[CytoScapeNode] = pydantic.Field(
|
52
52
|
default_factory=list,
|
53
53
|
description="Nodes of the Graph",
|
54
54
|
)
|
55
|
-
edges:
|
55
|
+
edges: list[CytoScapeEdge] = pydantic.Field(
|
56
56
|
default_factory=list,
|
57
57
|
description="Edges of the Graph",
|
58
58
|
)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Annotated, Literal, Optional, Union
|
2
2
|
from uuid import UUID
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic import Field
|
6
|
-
from typing_extensions import
|
6
|
+
from typing_extensions import Self
|
7
7
|
|
8
8
|
from classiq.interface.analyzer.analysis_params import MAX_FILE_LENGTH
|
9
9
|
from classiq.interface.enum_utils import StrEnum
|
@@ -11,7 +11,7 @@ from classiq.interface.exceptions import ClassiqValueError
|
|
11
11
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonEmptyString
|
12
12
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
13
13
|
|
14
|
-
Match =
|
14
|
+
Match = list[list[int]]
|
15
15
|
|
16
16
|
|
17
17
|
class GraphStatus(StrEnum):
|
@@ -29,8 +29,8 @@ class RbResults(VersionedModel):
|
|
29
29
|
average_error: float
|
30
30
|
A: float
|
31
31
|
B: float
|
32
|
-
success_probability:
|
33
|
-
parameters_error:
|
32
|
+
success_probability: list[float]
|
33
|
+
parameters_error: tuple[float, ...]
|
34
34
|
|
35
35
|
|
36
36
|
class DataID(pydantic.BaseModel):
|
@@ -58,19 +58,19 @@ class BasisGates(StrEnum):
|
|
58
58
|
|
59
59
|
|
60
60
|
class HardwareComparisonInformation(pydantic.BaseModel):
|
61
|
-
devices:
|
61
|
+
devices: list[str] = pydantic.Field(
|
62
62
|
default=..., description="Device which is used for the transpilation."
|
63
63
|
)
|
64
|
-
providers:
|
64
|
+
providers: list[str] = pydantic.Field(
|
65
65
|
default=..., description="Provider cloud of the device."
|
66
66
|
)
|
67
|
-
depth:
|
67
|
+
depth: list[pydantic.NonNegativeInt] = pydantic.Field(
|
68
68
|
default=..., description="Circuit depth."
|
69
69
|
)
|
70
|
-
multi_qubit_gate_count:
|
70
|
+
multi_qubit_gate_count: list[pydantic.NonNegativeInt] = pydantic.Field(
|
71
71
|
default=..., description="Number of multi qubit gates."
|
72
72
|
)
|
73
|
-
total_gate_count:
|
73
|
+
total_gate_count: list[pydantic.NonNegativeInt] = pydantic.Field(
|
74
74
|
default=..., description="Number of total gates."
|
75
75
|
)
|
76
76
|
|
@@ -105,32 +105,32 @@ class SingleHardwareInformation(pydantic.BaseModel):
|
|
105
105
|
|
106
106
|
class HardwareComparisonData(VersionedModel):
|
107
107
|
kind: Literal["hardware_comparison"] = Field(default="hardware_comparison")
|
108
|
-
data:
|
108
|
+
data: list[SingleHardwareInformation]
|
109
109
|
|
110
110
|
|
111
111
|
HardwareComparisonGraphType = Annotated[
|
112
112
|
Union[HardwareComparisonData, GraphResult], Field(discriminator="kind")
|
113
113
|
]
|
114
114
|
|
115
|
-
_HARDWARE_COMPARISON_TABLE_COLUMNS_NAMES:
|
115
|
+
_HARDWARE_COMPARISON_TABLE_COLUMNS_NAMES: dict[str, str] = {
|
116
116
|
s.upper(): s.capitalize() for s in SingleHardwareInformation.model_fields
|
117
117
|
}
|
118
118
|
|
119
119
|
|
120
120
|
class HardwareComparisonDataColumns(pydantic.BaseModel):
|
121
|
-
columns:
|
121
|
+
columns: dict[str, str] = _HARDWARE_COMPARISON_TABLE_COLUMNS_NAMES
|
122
122
|
|
123
123
|
|
124
124
|
class AvailableHardware(pydantic.BaseModel):
|
125
|
-
ibm_quantum: Optional[
|
125
|
+
ibm_quantum: Optional[dict[PydanticNonEmptyString, bool]] = pydantic.Field(
|
126
126
|
default=None,
|
127
127
|
description="available IBM Quantum devices with boolean indicates if a given device has enough qubits.",
|
128
128
|
)
|
129
|
-
azure_quantum: Optional[
|
129
|
+
azure_quantum: Optional[dict[PydanticNonEmptyString, bool]] = pydantic.Field(
|
130
130
|
default=None,
|
131
131
|
description="available Azure Quantum devices with boolean indicates if a given device has enough qubits.",
|
132
132
|
)
|
133
|
-
amazon_braket: Optional[
|
133
|
+
amazon_braket: Optional[dict[PydanticNonEmptyString, bool]] = pydantic.Field(
|
134
134
|
default=None,
|
135
135
|
description="available Amazon Braket devices with boolean indicates if a given device has enough qubits.",
|
136
136
|
)
|
@@ -163,7 +163,7 @@ class QuantumCircuitProperties(pydantic.BaseModel):
|
|
163
163
|
|
164
164
|
|
165
165
|
class NativeQuantumCircuitProperties(QuantumCircuitProperties):
|
166
|
-
native_gates:
|
166
|
+
native_gates: set[BasisGates] = pydantic.Field(
|
167
167
|
default=..., description="Native gates used for decomposition"
|
168
168
|
)
|
169
169
|
|
@@ -1,11 +1,7 @@
|
|
1
|
-
from collections.abc import Sequence
|
1
|
+
from collections.abc import Iterable as IterableType, Sequence
|
2
2
|
from typing import (
|
3
3
|
Any,
|
4
|
-
Iterable as IterableType,
|
5
|
-
List,
|
6
4
|
Optional,
|
7
|
-
Tuple,
|
8
|
-
Type,
|
9
5
|
Union,
|
10
6
|
)
|
11
7
|
|
@@ -16,8 +12,8 @@ from pydantic import ConfigDict, field_validator
|
|
16
12
|
|
17
13
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
18
14
|
|
19
|
-
DataList =
|
20
|
-
LabelsInt =
|
15
|
+
DataList = list[list[float]]
|
16
|
+
LabelsInt = list[int]
|
21
17
|
|
22
18
|
|
23
19
|
def listify(obj: Union[IterableType, ArrayLike]) -> list:
|
@@ -33,13 +29,13 @@ def listify(obj: Union[IterableType, ArrayLike]) -> list:
|
|
33
29
|
|
34
30
|
def validate_array_to_list(name: str) -> Any:
|
35
31
|
@field_validator(name, mode="before")
|
36
|
-
def _listify(cls:
|
32
|
+
def _listify(cls: type[pydantic.BaseModel], value: Any) -> Any:
|
37
33
|
return listify(value)
|
38
34
|
|
39
35
|
return _listify
|
40
36
|
|
41
37
|
|
42
|
-
Shape =
|
38
|
+
Shape = tuple[int, ...]
|
43
39
|
|
44
40
|
|
45
41
|
class QSVMInternalState(VersionedModel):
|
@@ -118,4 +114,4 @@ class QSVMPredictResult(VersionedModel):
|
|
118
114
|
|
119
115
|
|
120
116
|
Data = Union[DataList, np.ndarray]
|
121
|
-
Labels = Union[
|
117
|
+
Labels = Union[list[Any], np.ndarray]
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from
|
3
|
+
from collections.abc import Iterable
|
4
|
+
from typing import Any, Optional, Union
|
4
5
|
|
5
6
|
import pydantic
|
6
7
|
from pydantic import BaseModel
|
@@ -50,7 +51,7 @@ class BackendPreferences(BaseModel):
|
|
50
51
|
@classmethod
|
51
52
|
def batch_preferences(
|
52
53
|
cls, *, backend_names: Iterable[str], **kwargs: Any
|
53
|
-
) ->
|
54
|
+
) -> list[BackendPreferences]:
|
54
55
|
return [cls(backend_name=name, **kwargs) for name in backend_names]
|
55
56
|
|
56
57
|
def is_nvidia_backend(self) -> bool:
|
@@ -121,7 +122,7 @@ class AliceBobBackendPreferences(BackendPreferences):
|
|
121
122
|
)
|
122
123
|
|
123
124
|
@property
|
124
|
-
def parameters(self) ->
|
125
|
+
def parameters(self) -> dict[str, Any]:
|
125
126
|
parameters = {
|
126
127
|
"distance": self.distance,
|
127
128
|
"kappa1": self.kappa_1,
|
@@ -1,9 +1,8 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import TYPE_CHECKING,
|
3
|
+
from typing import TYPE_CHECKING, Annotated, Optional
|
4
4
|
|
5
5
|
from pydantic import BaseModel, ConfigDict, Field
|
6
|
-
from typing_extensions import Annotated
|
7
6
|
|
8
7
|
# This file is based on autogenerated code from: https://static.ionq.co/schemas/circuit-v0.json using
|
9
8
|
# https://pydantic-docs.helpmanual.io/datamodel_code_generator/
|
@@ -25,14 +24,14 @@ class Gate(BaseModel):
|
|
25
24
|
gate: PydanticGateName
|
26
25
|
target: Optional[int] = None
|
27
26
|
control: Optional[int] = None
|
28
|
-
targets: Optional[
|
29
|
-
controls: Optional[
|
27
|
+
targets: Optional[list[int]] = None
|
28
|
+
controls: Optional[list[int]] = None
|
30
29
|
model_config = ConfigDict(extra="allow")
|
31
30
|
|
32
31
|
|
33
32
|
class IonqQuantumCircuit(BaseModel):
|
34
33
|
qubits: int
|
35
|
-
circuit:
|
34
|
+
circuit: list[Gate]
|
36
35
|
model_config = ConfigDict(extra="allow")
|
37
36
|
|
38
37
|
@classmethod
|
@@ -1,7 +1,6 @@
|
|
1
|
-
from typing import TYPE_CHECKING
|
1
|
+
from typing import TYPE_CHECKING, Annotated
|
2
2
|
|
3
3
|
from pydantic import Field, StrictStr, constr
|
4
|
-
from typing_extensions import Annotated
|
5
4
|
|
6
5
|
AZURE_QUANTUM_RESOURCE_ID_REGEX = r"^/subscriptions/([a-fA-F0-9-]*)/resourceGroups/([^\s/]*)/providers/Microsoft\.Quantum/Workspaces/([^\s/]*)$"
|
7
6
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import itertools
|
4
|
-
from typing import
|
4
|
+
from typing import Union
|
5
5
|
|
6
6
|
import numpy as np
|
7
7
|
import pydantic
|
@@ -12,8 +12,8 @@ from classiq.interface.helpers.hashable_pydantic_base_model import (
|
|
12
12
|
HashablePydanticBaseModel,
|
13
13
|
)
|
14
14
|
|
15
|
-
LadderOperator =
|
16
|
-
FermionicOperatorTuple =
|
15
|
+
LadderOperator = tuple[str, int]
|
16
|
+
FermionicOperatorTuple = tuple["FermionicOperator", float]
|
17
17
|
|
18
18
|
_SUBSCRIPT_UNICODE_CHARS = {
|
19
19
|
"0": "\u2080",
|
@@ -118,7 +118,7 @@ class FermionicOperator(HashablePydanticBaseModel):
|
|
118
118
|
)
|
119
119
|
|
120
120
|
@property
|
121
|
-
def all_indices(self) ->
|
121
|
+
def all_indices(self) -> set[int]:
|
122
122
|
return {op[1] for op in self.op_list}
|
123
123
|
|
124
124
|
|
@@ -195,7 +195,7 @@ class SummedFermionicOperator(HashablePydanticBaseModel):
|
|
195
195
|
return True
|
196
196
|
|
197
197
|
@property
|
198
|
-
def _all_indices(self) ->
|
198
|
+
def _all_indices(self) -> set[int]:
|
199
199
|
return set(
|
200
200
|
itertools.chain.from_iterable(op.all_indices for op, _ in self.op_list)
|
201
201
|
)
|
@@ -1,9 +1,8 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Annotated, Literal, Optional, Union, cast
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import ConfigDict, Field
|
5
5
|
from pydantic_core.core_schema import ValidationInfo
|
6
|
-
from typing_extensions import Annotated
|
7
6
|
|
8
7
|
from classiq.interface.chemistry.fermionic_operator import SummedFermionicOperator
|
9
8
|
from classiq.interface.chemistry.molecule import Molecule
|
@@ -29,7 +28,7 @@ And use a list, and manually check its length
|
|
29
28
|
"""
|
30
29
|
NumSpinUpParticles = pydantic.NonNegativeInt
|
31
30
|
NumSpinDownParticles = pydantic.NonNegativeInt
|
32
|
-
NumParticles =
|
31
|
+
NumParticles = tuple[NumSpinUpParticles, NumSpinDownParticles]
|
33
32
|
|
34
33
|
|
35
34
|
class FermionMapping(StrEnum):
|
@@ -74,7 +73,7 @@ class MoleculeProblem(GroundStateProblem):
|
|
74
73
|
molecule: Molecule
|
75
74
|
basis: str = pydantic.Field(default="sto3g", description="Molecular basis set")
|
76
75
|
freeze_core: bool = pydantic.Field(default=False)
|
77
|
-
remove_orbitals:
|
76
|
+
remove_orbitals: list[int] = pydantic.Field(
|
78
77
|
default_factory=list, description="list of orbitals to remove"
|
79
78
|
)
|
80
79
|
|
@@ -85,7 +84,7 @@ class HamiltonianProblem(GroundStateProblem):
|
|
85
84
|
hamiltonian: SummedFermionicOperator = pydantic.Field(
|
86
85
|
description="Hamiltonian as a fermionic operator"
|
87
86
|
)
|
88
|
-
num_particles:
|
87
|
+
num_particles: list[pydantic.PositiveInt] = pydantic.Field(
|
89
88
|
description="Tuple containing the numbers of alpha particles and beta particles"
|
90
89
|
)
|
91
90
|
|
@@ -94,9 +93,9 @@ class HamiltonianProblem(GroundStateProblem):
|
|
94
93
|
def _validate_num_particles(
|
95
94
|
cls,
|
96
95
|
num_particles: Union[
|
97
|
-
|
96
|
+
list[Union[int, float]], tuple[Union[int, float], Union[int, float]]
|
98
97
|
],
|
99
|
-
) ->
|
98
|
+
) -> list[int]:
|
100
99
|
assert isinstance(num_particles, (list, tuple))
|
101
100
|
assert len(num_particles) == 2
|
102
101
|
|
@@ -105,7 +104,7 @@ class HamiltonianProblem(GroundStateProblem):
|
|
105
104
|
assert num_particles[0] >= 1
|
106
105
|
assert num_particles[1] >= 1
|
107
106
|
|
108
|
-
return cast(
|
107
|
+
return cast(list[int], num_particles)
|
109
108
|
|
110
109
|
|
111
110
|
CHEMISTRY_PROBLEMS = (MoleculeProblem, HamiltonianProblem)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Literal, Union
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import ConfigDict
|
@@ -19,7 +19,7 @@ class Atom(HashablePydanticBaseModel):
|
|
19
19
|
|
20
20
|
|
21
21
|
class Molecule(HashablePydanticBaseModel):
|
22
|
-
atoms:
|
22
|
+
atoms: list[Atom] = pydantic.Field(
|
23
23
|
description="A list of atoms each containing the atoms symbol and its (x,y,z) location",
|
24
24
|
min_length=1,
|
25
25
|
)
|
@@ -31,7 +31,7 @@ class Molecule(HashablePydanticBaseModel):
|
|
31
31
|
)
|
32
32
|
|
33
33
|
@property
|
34
|
-
def atoms_type(self) ->
|
34
|
+
def atoms_type(self) -> list[AtomType]:
|
35
35
|
return [(atom.symbol, [atom.x, atom.y, atom.z]) for atom in self.atoms]
|
36
36
|
|
37
37
|
@classmethod
|
@@ -42,7 +42,7 @@ class Molecule(HashablePydanticBaseModel):
|
|
42
42
|
|
43
43
|
@pydantic.field_validator("atoms", mode="before")
|
44
44
|
@classmethod
|
45
|
-
def _validate_atoms(cls, atoms:
|
45
|
+
def _validate_atoms(cls, atoms: list[Union[AtomType, Atom]]) -> list[Atom]:
|
46
46
|
return [cls._validate_atom(atom) for atom in atoms]
|
47
47
|
|
48
48
|
@staticmethod
|