classiq 0.43.3__py3-none-any.whl → 0.45.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 +8 -3
- classiq/_internals/api_wrapper.py +2 -2
- classiq/_internals/authentication/auth0.py +1 -1
- classiq/_internals/authentication/device.py +5 -1
- classiq/_internals/authentication/token_manager.py +5 -4
- classiq/_internals/client.py +5 -8
- classiq/_internals/config.py +1 -2
- classiq/_internals/host_checker.py +34 -13
- classiq/_internals/jobs.py +3 -3
- classiq/analyzer/analyzer.py +1 -1
- classiq/analyzer/analyzer_utilities.py +1 -1
- classiq/analyzer/rb.py +1 -1
- classiq/applications/chemistry/chemistry_model_constructor.py +13 -7
- classiq/applications/combinatorial_helpers/allowed_constraints.py +4 -1
- classiq/applications/combinatorial_helpers/arithmetic/isolation.py +1 -1
- classiq/applications/combinatorial_helpers/encoding_mapping.py +1 -1
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -1
- classiq/applications/combinatorial_helpers/optimization_model.py +1 -1
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +1 -1
- classiq/applications/combinatorial_helpers/pyomo_utils.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/encoding.py +1 -1
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +5 -4
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +1 -1
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +1 -1
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +1 -1
- classiq/applications/finance/finance_model_constructor.py +4 -3
- classiq/applications/grover/grover_model_constructor.py +7 -5
- classiq/applications/hamiltonian/__init__.py +0 -0
- classiq/applications/hamiltonian/pauli_decomposition.py +113 -0
- classiq/applications/qnn/circuit_utils.py +1 -1
- classiq/applications/qnn/datasets/dataset_base_classes.py +2 -1
- classiq/applications/qnn/datasets/dataset_not.py +2 -1
- classiq/applications/qnn/qlayer.py +3 -2
- classiq/applications/qnn/torch_utils.py +2 -1
- classiq/applications/qsvm/qsvm_model_constructor.py +1 -1
- classiq/execution/execution_session.py +1 -1
- classiq/execution/jobs.py +5 -2
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/cytoscape_graph.py +1 -2
- classiq/interface/analyzer/result.py +2 -3
- classiq/interface/ast_node.py +1 -18
- classiq/interface/backend/backend_preferences.py +11 -18
- classiq/interface/backend/ionq/ionq_quantum_program.py +1 -1
- classiq/interface/backend/pydantic_backend.py +0 -5
- classiq/interface/backend/quantum_backend_providers.py +4 -3
- classiq/interface/chemistry/fermionic_operator.py +1 -2
- classiq/interface/chemistry/ground_state_problem.py +2 -3
- classiq/interface/chemistry/molecule.py +1 -2
- classiq/interface/chemistry/operator.py +8 -10
- classiq/interface/combinatorial_optimization/encoding_types.py +1 -1
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +1 -1
- classiq/interface/combinatorial_optimization/solver_types.py +1 -1
- classiq/interface/debug_info/__init__.py +0 -0
- classiq/interface/debug_info/debug_info.py +32 -0
- classiq/{exceptions.py → interface/exceptions.py} +4 -0
- classiq/interface/executor/aws_execution_cost.py +2 -2
- classiq/interface/executor/execution_preferences.py +2 -47
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/optimizer_preferences.py +2 -3
- classiq/interface/executor/quantum_code.py +1 -2
- classiq/interface/executor/quantum_instruction_set.py +2 -2
- classiq/interface/executor/register_initialization.py +1 -2
- classiq/interface/executor/result.py +29 -14
- classiq/interface/finance/function_input.py +6 -11
- classiq/interface/generator/amplitude_loading.py +2 -3
- classiq/interface/generator/ansatz_library.py +1 -1
- classiq/interface/generator/application_apis/arithmetic_declarations.py +8 -5
- classiq/interface/generator/application_apis/chemistry_declarations.py +78 -60
- classiq/interface/generator/application_apis/combinatorial_optimization_declarations.py +19 -10
- classiq/interface/generator/application_apis/entangler_declarations.py +11 -6
- classiq/interface/generator/application_apis/finance_declarations.py +37 -44
- classiq/interface/generator/application_apis/qsvm_declarations.py +21 -15
- classiq/interface/generator/arith/arithmetic.py +10 -8
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +1 -2
- classiq/interface/generator/arith/arithmetic_expression_abc.py +22 -3
- classiq/interface/generator/arith/arithmetic_expression_parser.py +3 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +1 -2
- classiq/interface/generator/arith/arithmetic_param_getters.py +1 -2
- classiq/interface/generator/arith/arithmetic_result_builder.py +15 -11
- classiq/interface/generator/arith/ast_node_rewrite.py +1 -1
- classiq/interface/generator/arith/binary_ops.py +7 -7
- classiq/interface/generator/arith/endianness.py +1 -1
- classiq/interface/generator/arith/extremum_operations.py +44 -21
- classiq/interface/generator/arith/logical_ops.py +1 -2
- classiq/interface/generator/arith/register_user_input.py +1 -2
- classiq/interface/generator/arith/unary_ops.py +1 -2
- classiq/interface/generator/arith/uncomputation_methods.py +1 -1
- classiq/interface/generator/chemistry_function_params.py +1 -2
- classiq/interface/generator/circuit_code/circuit_code.py +1 -2
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -2
- classiq/interface/generator/commuting_pauli_exponentiation.py +1 -2
- classiq/interface/generator/constant.py +1 -1
- classiq/interface/generator/control_state.py +1 -2
- classiq/interface/generator/custom_ansatz.py +1 -2
- classiq/interface/generator/expressions/atomic_expression_functions.py +1 -0
- classiq/interface/generator/expressions/enums/finance_functions.py +4 -5
- classiq/interface/generator/expressions/evaluated_expression.py +1 -2
- classiq/interface/generator/expressions/expression.py +1 -2
- classiq/interface/generator/expressions/expression_constants.py +3 -1
- classiq/interface/generator/expressions/non_symbolic_expr.py +1 -1
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +53 -70
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +2 -7
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +35 -0
- classiq/interface/generator/expressions/qmod_sized_proxy.py +1 -1
- classiq/interface/generator/expressions/sympy_supported_expressions.py +2 -1
- classiq/interface/generator/function_params.py +2 -3
- classiq/interface/generator/functions/builtins/core_library/__init__.py +4 -2
- classiq/interface/generator/functions/builtins/core_library/atomic_quantum_functions.py +41 -41
- classiq/interface/generator/functions/builtins/core_library/exponentiation_functions.py +52 -42
- classiq/interface/generator/functions/builtins/open_lib_functions.py +1095 -3347
- classiq/interface/generator/functions/builtins/quantum_operators.py +9 -22
- classiq/interface/generator/functions/classical_function_declaration.py +14 -6
- classiq/interface/generator/functions/classical_type.py +7 -114
- classiq/interface/generator/functions/concrete_types.py +55 -0
- classiq/interface/generator/functions/function_declaration.py +10 -10
- classiq/interface/generator/functions/port_declaration.py +1 -2
- classiq/interface/generator/functions/type_name.py +80 -0
- classiq/interface/generator/generated_circuit_data.py +3 -3
- classiq/interface/generator/grover_diffuser.py +1 -2
- classiq/interface/generator/grover_operator.py +1 -2
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +1 -2
- classiq/interface/generator/hamiltonian_evolution/suzuki_trotter.py +1 -2
- classiq/interface/generator/hardware/hardware_data.py +1 -2
- classiq/interface/generator/hardware_efficient_ansatz.py +2 -3
- classiq/interface/generator/hartree_fock.py +1 -2
- classiq/interface/generator/linear_pauli_rotations.py +1 -2
- classiq/interface/generator/mcmt_method.py +1 -1
- classiq/interface/generator/mcu.py +1 -2
- classiq/interface/generator/mcx.py +1 -2
- classiq/interface/generator/model/constraints.py +2 -3
- classiq/interface/generator/model/model.py +12 -2
- classiq/interface/generator/model/preferences/preferences.py +7 -3
- classiq/interface/generator/model/quantum_register.py +1 -2
- classiq/interface/generator/oracles/arithmetic_oracle.py +1 -2
- classiq/interface/generator/oracles/custom_oracle.py +1 -2
- classiq/interface/generator/oracles/oracle_abc.py +1 -2
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +1 -2
- classiq/interface/generator/preferences/optimization.py +1 -2
- classiq/interface/generator/qpe.py +1 -2
- classiq/interface/generator/qsvm.py +2 -3
- classiq/interface/generator/quantum_function_call.py +4 -2
- classiq/interface/generator/quantum_program.py +6 -7
- classiq/interface/generator/range_types.py +1 -1
- classiq/interface/generator/register_role.py +8 -2
- classiq/interface/generator/slice_parsing_utils.py +1 -2
- classiq/interface/generator/standard_gates/controlled_standard_gates.py +1 -2
- classiq/interface/generator/state_preparation/metrics.py +2 -3
- classiq/interface/generator/state_preparation/state_preparation.py +1 -2
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +1 -3
- classiq/interface/generator/transpiler_basis_gates.py +1 -1
- classiq/interface/generator/types/builtin_enum_declarations.py +38 -45
- classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +1 -2
- classiq/interface/generator/types/enum_declaration.py +1 -2
- classiq/interface/generator/types/qstruct_declaration.py +17 -0
- classiq/interface/generator/types/struct_declaration.py +2 -3
- classiq/interface/generator/ucc.py +1 -2
- classiq/interface/generator/unitary_gate.py +1 -2
- classiq/interface/generator/validations/flow_graph.py +1 -2
- classiq/interface/generator/validations/validator_functions.py +1 -2
- classiq/interface/hardware.py +1 -1
- classiq/interface/helpers/validation_helpers.py +2 -19
- classiq/interface/ide/visual_model.py +10 -4
- classiq/interface/interface_version.py +1 -0
- classiq/interface/jobs.py +2 -3
- classiq/interface/model/bind_operation.py +26 -7
- classiq/interface/model/classical_parameter_declaration.py +8 -5
- classiq/interface/model/control.py +5 -5
- classiq/interface/model/handle_binding.py +185 -12
- classiq/interface/model/inplace_binary_operation.py +17 -6
- classiq/interface/model/model.py +29 -7
- classiq/interface/model/native_function_definition.py +8 -4
- classiq/interface/model/parameter.py +13 -0
- classiq/interface/model/port_declaration.py +21 -4
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +22 -8
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +30 -6
- classiq/interface/model/quantum_expressions/quantum_expression.py +4 -9
- classiq/interface/model/quantum_function_call.py +136 -194
- classiq/interface/model/quantum_function_declaration.py +147 -165
- classiq/interface/model/quantum_lambda_function.py +23 -6
- classiq/interface/model/quantum_statement.py +34 -8
- classiq/interface/model/quantum_type.py +41 -11
- classiq/interface/model/quantum_variable_declaration.py +1 -1
- classiq/interface/model/statement_block.py +2 -0
- classiq/interface/model/validation_handle.py +8 -2
- classiq/interface/server/global_versions.py +4 -4
- classiq/interface/server/routes.py +2 -0
- classiq/interface/source_reference.py +59 -0
- classiq/qmod/__init__.py +2 -3
- classiq/qmod/builtins/classical_execution_primitives.py +1 -1
- classiq/qmod/builtins/functions.py +39 -11
- classiq/qmod/builtins/operations.py +172 -41
- classiq/qmod/classical_function.py +1 -1
- classiq/qmod/declaration_inferrer.py +102 -57
- classiq/qmod/expression_query.py +1 -1
- classiq/qmod/model_state_container.py +2 -0
- classiq/qmod/native/pretty_printer.py +71 -53
- classiq/qmod/pretty_print/pretty_printer.py +98 -52
- classiq/qmod/qfunc.py +11 -5
- classiq/qmod/qmod_constant.py +1 -1
- classiq/qmod/qmod_parameter.py +27 -4
- classiq/qmod/qmod_variable.py +405 -174
- classiq/qmod/quantum_callable.py +3 -3
- classiq/qmod/quantum_expandable.py +128 -68
- classiq/qmod/quantum_function.py +24 -5
- classiq/qmod/semantics/annotation.py +13 -15
- classiq/qmod/semantics/error_manager.py +36 -10
- classiq/qmod/semantics/static_semantics_visitor.py +164 -76
- classiq/qmod/semantics/validation/func_call_validation.py +43 -97
- classiq/qmod/semantics/validation/handle_validation.py +85 -0
- classiq/qmod/semantics/validation/types_validation.py +108 -1
- classiq/qmod/symbolic.py +2 -1
- classiq/qmod/type_attribute_remover.py +32 -0
- classiq/qmod/utilities.py +26 -5
- classiq/{interface/ide/show.py → show.py} +1 -1
- {classiq-0.43.3.dist-info → classiq-0.45.0.dist-info}/METADATA +3 -3
- {classiq-0.43.3.dist-info → classiq-0.45.0.dist-info}/RECORD +219 -207
- classiq/qmod/qmod_struct.py +0 -13
- /classiq/{_internals → interface}/enum_utils.py +0 -0
- {classiq-0.43.3.dist-info → classiq-0.45.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
from typing import List, Tuple, Union
|
2
|
+
|
3
|
+
import numpy as np
|
4
|
+
from sympy import fwht
|
5
|
+
|
6
|
+
from classiq.qmod import ( # type:ignore[attr-defined]
|
7
|
+
Pauli,
|
8
|
+
PauliTerm,
|
9
|
+
)
|
10
|
+
|
11
|
+
ATOL = 1e-12
|
12
|
+
PAULI_MATRICES_DICT = {
|
13
|
+
Pauli.I: np.array([[1, 0], [0, 1]], dtype=np.complex128),
|
14
|
+
Pauli.Z: np.array([[1, 0], [0, -1]], dtype=np.complex128),
|
15
|
+
Pauli.X: np.array([[0, 1], [1, 0]], dtype=np.complex128),
|
16
|
+
Pauli.Y: np.array([[0, -1j], [1j, 0]], dtype=np.complex128),
|
17
|
+
}
|
18
|
+
|
19
|
+
|
20
|
+
def _get_pauli_string(set_index: int, term_index: int, num_qubits: int) -> List[Pauli]:
|
21
|
+
"""
|
22
|
+
The basis of 4^N Pauli strings on N qubits can be partitioned to 2^N sets, each contains 2^N Pauli strings.
|
23
|
+
In the k-th set we have Pauli strings of the form s_1s_2...s_N, where s_j is in {I,Z} if k_j is 0,
|
24
|
+
and in {X,iY} if k_j=1. The function get_pauli_string returns the m-th Pauli string in the k-th set of Pauli strings
|
25
|
+
"""
|
26
|
+
|
27
|
+
# returns the Pauli (I,Z) or (iY, X) appearing in the pauli_index position for a given set
|
28
|
+
def _get_paulis_for_set(set_index: int, pauli_index: int) -> Tuple[Pauli, Pauli]:
|
29
|
+
if (set_index >> pauli_index) & 1:
|
30
|
+
return Pauli.Y, Pauli.X
|
31
|
+
else:
|
32
|
+
return Pauli.Z, Pauli.I
|
33
|
+
|
34
|
+
return [
|
35
|
+
(
|
36
|
+
_get_paulis_for_set(set_index, s)[0]
|
37
|
+
if (term_index >> s) & 1
|
38
|
+
else _get_paulis_for_set(set_index, s)[1]
|
39
|
+
)
|
40
|
+
for s in range(num_qubits)
|
41
|
+
][::-1]
|
42
|
+
|
43
|
+
|
44
|
+
def _coefficents_for_set(mat: np.ndarray, set_index: int) -> list:
|
45
|
+
"""
|
46
|
+
The 2^N coefficients in a 2^N x 2^N matrix that are decomposed to the elements
|
47
|
+
in the k-th set are the indices [i,j] such that i^j=k
|
48
|
+
The function coefficents_for_set returns the matrix entries that are decomposed to the same Pauli strigs set
|
49
|
+
"""
|
50
|
+
return [mat[k, k ^ set_index] / len(mat) for k in range(len(mat))]
|
51
|
+
|
52
|
+
|
53
|
+
def _get_signed_coefficient(
|
54
|
+
c: complex, k: int, i: int, is_hermitian: bool
|
55
|
+
) -> Union[complex, float]:
|
56
|
+
# correct from iY to Y
|
57
|
+
coef = complex((1j) ** ((i & k).bit_count()) * c)
|
58
|
+
if is_hermitian:
|
59
|
+
return coef.real
|
60
|
+
else:
|
61
|
+
return coef
|
62
|
+
|
63
|
+
|
64
|
+
def matrix_to_hamiltonian(
|
65
|
+
mat: np.ndarray, tol: float = ATOL, is_hermitian: bool = True
|
66
|
+
) -> List[PauliTerm]:
|
67
|
+
"""
|
68
|
+
The decomposition per set is done by the Walsh-Hadamard transform,
|
69
|
+
since the transformation between {e_0,e_3} ({e_1,e_2}) to {I,Z} ({X,iY}) is the Hadamard matrix.
|
70
|
+
"""
|
71
|
+
mat.shape[0] != 0, "matrix is of size 0"
|
72
|
+
if is_hermitian:
|
73
|
+
assert np.allclose(
|
74
|
+
mat, np.conjugate(mat.T)
|
75
|
+
), "Matrix is not hermitian, please pass is_hermitian=False"
|
76
|
+
assert mat.shape[0] == mat.shape[1], "Matrix is not square"
|
77
|
+
mat_dimension = mat.shape[0]
|
78
|
+
assert mat_dimension.bit_count() == 1, "Matrix dimension is not a power of 2"
|
79
|
+
num_qubits = (mat_dimension - 1).bit_length()
|
80
|
+
hamiltonian = []
|
81
|
+
for k in range(2**num_qubits):
|
82
|
+
coef = fwht(
|
83
|
+
_coefficents_for_set(mat, k)
|
84
|
+
) # the transformation per set is given by the Walsh-Hadamard transform
|
85
|
+
hamiltonian += [
|
86
|
+
PauliTerm(
|
87
|
+
pauli=_get_pauli_string(k, i, num_qubits),
|
88
|
+
coefficient=_get_signed_coefficient(coef[i], k, i, is_hermitian),
|
89
|
+
)
|
90
|
+
for i in range(2**num_qubits)
|
91
|
+
if abs(coef[i]) > tol
|
92
|
+
]
|
93
|
+
return hamiltonian
|
94
|
+
|
95
|
+
|
96
|
+
# convert a single puali string of length N to 2**N X 2**N matrix
|
97
|
+
def pauli_string_to_mat(seq: List[Pauli]) -> np.ndarray:
|
98
|
+
real_matrix = PAULI_MATRICES_DICT[seq[0]]
|
99
|
+
for p in seq[1:]:
|
100
|
+
real_matrix = np.kron(real_matrix, PAULI_MATRICES_DICT[p])
|
101
|
+
return real_matrix
|
102
|
+
|
103
|
+
|
104
|
+
# return matrix from hamiltonian
|
105
|
+
def hamiltonian_to_matrix(hamiltonian: List[PauliTerm]) -> np.ndarray:
|
106
|
+
matrix = np.zeros(
|
107
|
+
[2 ** len(hamiltonian[0].pauli), 2 ** len(hamiltonian[0].pauli)],
|
108
|
+
dtype=np.complex_,
|
109
|
+
)
|
110
|
+
for p in hamiltonian:
|
111
|
+
matrix += p.coefficient * pauli_string_to_mat(p.pauli)
|
112
|
+
|
113
|
+
return matrix
|
@@ -4,12 +4,12 @@ from typing import Iterable, List, Tuple, Union
|
|
4
4
|
|
5
5
|
from torch import Tensor
|
6
6
|
|
7
|
+
from classiq.interface.exceptions import ClassiqQNNError, ClassiqValueError
|
7
8
|
from classiq.interface.generator.circuit_code.types_and_constants import QasmVersion
|
8
9
|
from classiq.interface.generator.model.preferences.preferences import QuantumFormat
|
9
10
|
from classiq.interface.generator.quantum_program import QuantumProgram
|
10
11
|
|
11
12
|
from classiq.applications.qnn.types import Arguments, Circuit
|
12
|
-
from classiq.exceptions import ClassiqQNNError, ClassiqValueError
|
13
13
|
|
14
14
|
WEIGHT_INITIALS = ["weight_", "w_"]
|
15
15
|
INPUT_INITIALS = ["input_", "i_"]
|
@@ -4,8 +4,9 @@ from typing import List, Literal, Optional, Sequence, Tuple, TypeVar, Union
|
|
4
4
|
from torch import Tensor, tensor
|
5
5
|
from torch.utils.data import Dataset
|
6
6
|
|
7
|
+
from classiq.interface.exceptions import ClassiqIndexError, ClassiqValueError
|
8
|
+
|
7
9
|
from classiq.applications.qnn.types import DataAndLabel, Transform
|
8
|
-
from classiq.exceptions import ClassiqIndexError, ClassiqValueError
|
9
10
|
|
10
11
|
T = TypeVar("T")
|
11
12
|
|
@@ -1,10 +1,11 @@
|
|
1
|
+
from classiq.interface.exceptions import ClassiqIndexError
|
2
|
+
|
1
3
|
from classiq.applications.qnn.datasets.dataset_base_classes import MyDataset
|
2
4
|
from classiq.applications.qnn.datasets.datasets_utils import (
|
3
5
|
all_bits_to_one,
|
4
6
|
all_bits_to_zero,
|
5
7
|
)
|
6
8
|
from classiq.applications.qnn.types import DataAndLabel
|
7
|
-
from classiq.exceptions import ClassiqIndexError
|
8
9
|
|
9
10
|
|
10
11
|
class DatasetNot(MyDataset):
|
@@ -6,6 +6,8 @@ import torch.nn as nn
|
|
6
6
|
from torch import Tensor
|
7
7
|
from torch.nn.parameter import Parameter
|
8
8
|
|
9
|
+
from classiq.interface.exceptions import ClassiqQNNError, ClassiqTorchError
|
10
|
+
|
9
11
|
from classiq.applications.qnn.circuit_utils import (
|
10
12
|
extract_parameters,
|
11
13
|
is_single_layer_circuit,
|
@@ -26,7 +28,6 @@ from classiq.applications.qnn.types import (
|
|
26
28
|
MultipleArguments,
|
27
29
|
PostProcessFunction,
|
28
30
|
)
|
29
|
-
from classiq.exceptions import ClassiqQNNError, ClassiqTorchError
|
30
31
|
from classiq.synthesis import SerializedQuantumProgram
|
31
32
|
|
32
33
|
|
@@ -181,6 +182,6 @@ class QLayer(nn.Module):
|
|
181
182
|
self.weight = Parameter(value)
|
182
183
|
|
183
184
|
def forward(self, x: Tensor) -> Tensor:
|
184
|
-
return QLayerFunction.apply(
|
185
|
+
return QLayerFunction.apply(
|
185
186
|
x, self.weight, self.quantum_program, self._execute, self._post_process
|
186
187
|
)
|
@@ -6,6 +6,8 @@ import torch
|
|
6
6
|
import torch.nn as nn
|
7
7
|
from torch import Tensor
|
8
8
|
|
9
|
+
from classiq.interface.exceptions import ClassiqValueError
|
10
|
+
|
9
11
|
from classiq.applications.qnn.circuit_utils import is_single_layer_circuit
|
10
12
|
from classiq.applications.qnn.types import (
|
11
13
|
ExecuteFuncitonOnlyArguments,
|
@@ -13,7 +15,6 @@ from classiq.applications.qnn.types import (
|
|
13
15
|
Shape,
|
14
16
|
TensorToArgumentsCallable,
|
15
17
|
)
|
16
|
-
from classiq.exceptions import ClassiqValueError
|
17
18
|
|
18
19
|
|
19
20
|
def get_shape_second_dimension(shape: torch.Size) -> int:
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from typing import Any, List, Tuple
|
2
2
|
|
3
3
|
from classiq.interface.applications.qsvm import DataList, LabelsInt
|
4
|
+
from classiq.interface.exceptions import ClassiqValueError
|
4
5
|
from classiq.interface.generator.expressions.expression import Expression
|
5
6
|
from classiq.interface.generator.functions.port_declaration import (
|
6
7
|
PortDeclarationDirection,
|
@@ -11,7 +12,6 @@ from classiq.interface.model.native_function_definition import NativeFunctionDef
|
|
11
12
|
from classiq.interface.model.port_declaration import PortDeclaration
|
12
13
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
13
14
|
|
14
|
-
from classiq.exceptions import ClassiqValueError
|
15
15
|
from classiq.qmod.builtins.enums import Pauli, QSVMFeatureMapEntanglement
|
16
16
|
from classiq.qmod.utilities import qmod_val_to_expr_str
|
17
17
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import json
|
2
2
|
from typing import Any, Callable, Dict, List, Optional, Tuple, Union, cast
|
3
3
|
|
4
|
+
from classiq.interface.exceptions import ClassiqValueError
|
4
5
|
from classiq.interface.executor.execution_preferences import ExecutionPreferences
|
5
6
|
from classiq.interface.executor.execution_result import ResultsCollection
|
6
7
|
from classiq.interface.executor.result import (
|
@@ -16,7 +17,6 @@ from classiq.applications.combinatorial_helpers.pauli_helpers.pauli_utils import
|
|
16
17
|
_pauli_dict_to_str,
|
17
18
|
_pauli_terms_to_qmod,
|
18
19
|
)
|
19
|
-
from classiq.exceptions import ClassiqValueError
|
20
20
|
from classiq.executor import execute
|
21
21
|
from classiq.qmod.builtins import PauliTerm
|
22
22
|
from classiq.qmod.builtins.classical_execution_primitives import (
|
classiq/execution/jobs.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import webbrowser
|
2
2
|
from datetime import datetime
|
3
|
-
from typing import List, Optional, Union
|
3
|
+
from typing import Any, List, Optional, Union
|
4
4
|
from urllib.parse import urljoin
|
5
5
|
|
6
|
+
from classiq.interface.exceptions import ClassiqAPIError
|
6
7
|
from classiq.interface.execution.jobs import ExecutionJobDetailsV1
|
7
8
|
from classiq.interface.executor.execution_request import ExecutionJobDetails
|
8
9
|
from classiq.interface.executor.execution_result import ResultsCollection
|
@@ -13,7 +14,6 @@ from classiq._internals.api_wrapper import CLASSIQ_ACCEPT_HEADER, ApiWrapper
|
|
13
14
|
from classiq._internals.async_utils import syncify_function
|
14
15
|
from classiq._internals.client import client
|
15
16
|
from classiq._internals.jobs import JobID, JobPoller
|
16
|
-
from classiq.exceptions import ClassiqAPIError
|
17
17
|
|
18
18
|
_JobDetails = Union[ExecutionJobDetails, ExecutionJobDetailsV1]
|
19
19
|
|
@@ -109,6 +109,9 @@ class ExecutionJob:
|
|
109
109
|
|
110
110
|
result = syncify_function(result_async)
|
111
111
|
|
112
|
+
def result_value(self, *args: Any, **kwargs: Any) -> Any:
|
113
|
+
return self.result(*args, **kwargs)[0].value
|
114
|
+
|
112
115
|
async def poll_async(self, timeout_sec: Optional[float] = None) -> None:
|
113
116
|
if not self.status.is_final():
|
114
117
|
await self._poll_job(timeout_sec=timeout_sec)
|
classiq/interface/_version.py
CHANGED
@@ -2,10 +2,9 @@ from typing import Any, Dict, List, Optional
|
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.enum_utils import StrEnum
|
5
6
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
6
7
|
|
7
|
-
from classiq._internals.enum_utils import StrEnum
|
8
|
-
|
9
8
|
|
10
9
|
class CytoScapePosition(pydantic.BaseModel):
|
11
10
|
x: int = pydantic.Field(
|
@@ -6,12 +6,11 @@ from pydantic import Field
|
|
6
6
|
from typing_extensions import Annotated
|
7
7
|
|
8
8
|
from classiq.interface.analyzer.analysis_params import MAX_FILE_LENGTH
|
9
|
+
from classiq.interface.enum_utils import StrEnum
|
10
|
+
from classiq.interface.exceptions import ClassiqValueError
|
9
11
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonEmptyString
|
10
12
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
11
13
|
|
12
|
-
from classiq._internals.enum_utils import StrEnum
|
13
|
-
from classiq.exceptions import ClassiqValueError
|
14
|
-
|
15
14
|
Match = List[List[int]]
|
16
15
|
|
17
16
|
|
classiq/interface/ast_node.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import os
|
2
1
|
from typing import Optional
|
3
2
|
|
4
3
|
import pydantic
|
@@ -6,23 +5,7 @@ import pydantic
|
|
6
5
|
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
7
6
|
HashablePydanticBaseModel,
|
8
7
|
)
|
9
|
-
|
10
|
-
|
11
|
-
class SourceReference(HashablePydanticBaseModel):
|
12
|
-
start_line: int
|
13
|
-
start_column: int
|
14
|
-
end_line: int
|
15
|
-
end_column: int
|
16
|
-
file_name: Optional[str] = pydantic.Field(default=None)
|
17
|
-
|
18
|
-
def __str__(self) -> str:
|
19
|
-
file_string = (
|
20
|
-
f"file {os.path.basename(self.file_name)} " if self.file_name else ""
|
21
|
-
)
|
22
|
-
start_character_string = (
|
23
|
-
f" character {self.start_column + 1}" if self.start_column > 0 else ""
|
24
|
-
)
|
25
|
-
return f"{file_string}line {self.start_line + 1}{start_character_string}"
|
8
|
+
from classiq.interface.source_reference import SourceReference
|
26
9
|
|
27
10
|
|
28
11
|
class ASTNode(HashablePydanticBaseModel):
|
@@ -1,10 +1,9 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from datetime import timedelta
|
4
3
|
from typing import Any, Dict, Iterable, List, Optional, Union
|
5
4
|
|
6
5
|
import pydantic
|
7
|
-
from pydantic import BaseModel,
|
6
|
+
from pydantic import BaseModel, validator
|
8
7
|
|
9
8
|
from classiq.interface.backend import pydantic_backend
|
10
9
|
from classiq.interface.backend.quantum_backend_providers import (
|
@@ -19,11 +18,10 @@ from classiq.interface.backend.quantum_backend_providers import (
|
|
19
18
|
ProviderTypeVendor,
|
20
19
|
ProviderVendor,
|
21
20
|
)
|
21
|
+
from classiq.interface.exceptions import ClassiqValueError
|
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
|
-
|
27
25
|
|
28
26
|
class BackendPreferences(BaseModel):
|
29
27
|
# Due to the way the field is currently implemented, i.e. it redefined with different types
|
@@ -56,9 +54,6 @@ class BackendPreferences(BaseModel):
|
|
56
54
|
return False
|
57
55
|
|
58
56
|
|
59
|
-
AWS_DEFAULT_JOB_TIMEOUT_SECONDS = int(timedelta(minutes=240).total_seconds())
|
60
|
-
|
61
|
-
|
62
57
|
class AliceBobBackendPreferences(BackendPreferences):
|
63
58
|
backend_service_provider: ProviderTypeVendor.ALICE_BOB
|
64
59
|
distance: Optional[int] = pydantic.Field(
|
@@ -76,7 +71,6 @@ class AliceBobBackendPreferences(BackendPreferences):
|
|
76
71
|
api_key: pydantic_backend.PydanticAliceBobApiKeyType = pydantic.Field(
|
77
72
|
..., description="AliceBob API key"
|
78
73
|
)
|
79
|
-
_parameters: Dict[str, Any] = PrivateAttr(default_factory=dict)
|
80
74
|
|
81
75
|
@pydantic.root_validator(pre=True)
|
82
76
|
def _set_backend_service_provider(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
@@ -86,14 +80,13 @@ class AliceBobBackendPreferences(BackendPreferences):
|
|
86
80
|
|
87
81
|
@property
|
88
82
|
def parameters(self) -> Dict[str, Any]:
|
89
|
-
|
83
|
+
parameters = {
|
90
84
|
"distance": self.distance,
|
91
|
-
"
|
92
|
-
"
|
93
|
-
"
|
85
|
+
"kappa1": self.kappa_1,
|
86
|
+
"kappa2": self.kappa_2,
|
87
|
+
"averageNbPhotons": self.average_nb_photons,
|
94
88
|
}
|
95
|
-
|
96
|
-
return self._parameters
|
89
|
+
return {k: v for k, v in parameters.items() if v is not None}
|
97
90
|
|
98
91
|
|
99
92
|
class ClassiqBackendPreferences(BackendPreferences):
|
@@ -118,10 +111,6 @@ class AwsBackendPreferences(BackendPreferences):
|
|
118
111
|
s3_folder: pydantic_backend.PydanticS3BucketKey = pydantic.Field(
|
119
112
|
description="S3 Folder Path Within The S3 Bucket"
|
120
113
|
)
|
121
|
-
job_timeout: pydantic_backend.PydanticExecutionTimeout = pydantic.Field(
|
122
|
-
description="Timeout for Jobs sent for execution in seconds.",
|
123
|
-
default=AWS_DEFAULT_JOB_TIMEOUT_SECONDS,
|
124
|
-
)
|
125
114
|
|
126
115
|
@validator("s3_bucket_name")
|
127
116
|
def _validate_s3_bucket_name(
|
@@ -156,6 +145,10 @@ class IBMBackendPreferences(BackendPreferences):
|
|
156
145
|
default_factory=IBMBackendProvider,
|
157
146
|
description="Provider specs. for identifying a single IBM Quantum provider.",
|
158
147
|
)
|
148
|
+
qctrl_api_key: Optional[str] = pydantic.Field(
|
149
|
+
default=None,
|
150
|
+
description="QCTRL API key to access QCTRL optimization abilities",
|
151
|
+
)
|
159
152
|
|
160
153
|
@pydantic.root_validator(pre=True)
|
161
154
|
def _set_backend_service_provider(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
@@ -37,7 +37,7 @@ class IonqQuantumCircuit(BaseModel):
|
|
37
37
|
circuit: List[Gate]
|
38
38
|
|
39
39
|
# Ionq changes format sometimes.
|
40
|
-
# One example is that `
|
40
|
+
# One example is that `IonqQuantumCircuit` got a field name "gateset" with the value "qis"
|
41
41
|
# Another is that `Gate` got a field named "rotation"
|
42
42
|
class Config:
|
43
43
|
extra = pydantic.Extra.allow
|
@@ -1,4 +1,3 @@
|
|
1
|
-
from datetime import timedelta
|
2
1
|
from typing import TYPE_CHECKING
|
3
2
|
|
4
3
|
import pydantic
|
@@ -11,12 +10,10 @@ INVALID_API_KEY: str = _IONQ_API_KEY_LENGTH * "a"
|
|
11
10
|
INVALID_API_KEY_ALICE_BOB: str = _ALICE_BOB_API_KEY_LENGTH * "a"
|
12
11
|
INVALID_EMAIL_OQC: str = "aa@aa.aa"
|
13
12
|
INVALID_PASSWORD_OQC: str = "Aa1!Aa1!"
|
14
|
-
MAX_EXECUTION_TIMEOUT_SECONDS = timedelta(hours=4).total_seconds()
|
15
13
|
|
16
14
|
EXECUTION_PARAMETER_PATTERN = "[_a-z][_a-z0-9]*"
|
17
15
|
|
18
16
|
if TYPE_CHECKING:
|
19
|
-
PydanticExecutionTimeout = int
|
20
17
|
PydanticAwsRoleArn = str
|
21
18
|
PydanticS3BucketKey = str
|
22
19
|
PydanticS3BucketName = str
|
@@ -42,8 +39,6 @@ else:
|
|
42
39
|
|
43
40
|
PydanticAliceBobApiKeyType = pydantic.constr(min_length=1, strip_whitespace=True)
|
44
41
|
|
45
|
-
PydanticExecutionTimeout = pydantic.conint(gt=0, le=MAX_EXECUTION_TIMEOUT_SECONDS)
|
46
|
-
|
47
42
|
PydanticArgumentNameType = pydantic.constr(regex="[_a-zA-Z][_a-zA-Z0-9]*")
|
48
43
|
|
49
44
|
PydanticExecutionParameter = pydantic.constr(regex=EXECUTION_PARAMETER_PATTERN)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from typing import Literal, Union
|
2
2
|
|
3
|
-
from classiq.
|
3
|
+
from classiq.interface.enum_utils import StrEnum
|
4
4
|
|
5
5
|
|
6
6
|
class AnalyzerProviderVendor(StrEnum):
|
@@ -41,8 +41,9 @@ class ClassiqSimulatorBackendNames(StrEnum):
|
|
41
41
|
class IonqBackendNames(StrEnum):
|
42
42
|
SIMULATOR = "simulator"
|
43
43
|
HARMONY = "qpu.harmony"
|
44
|
-
|
45
|
-
|
44
|
+
ARIA_1 = "qpu.aria-1"
|
45
|
+
ARIA_2 = "qpu.aria-2"
|
46
|
+
FORTE_1 = "qpu.forte-1"
|
46
47
|
|
47
48
|
|
48
49
|
class AzureQuantumBackendNames(StrEnum):
|
@@ -6,12 +6,11 @@ from typing import Set, Tuple, Union
|
|
6
6
|
import numpy as np
|
7
7
|
import pydantic
|
8
8
|
|
9
|
+
from classiq.interface.exceptions import ClassiqValueError
|
9
10
|
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
10
11
|
HashablePydanticBaseModel,
|
11
12
|
)
|
12
13
|
|
13
|
-
from classiq.exceptions import ClassiqValueError
|
14
|
-
|
15
14
|
LadderOperator = Tuple[str, int]
|
16
15
|
FermionicOperatorTuple = Tuple["FermionicOperator", float]
|
17
16
|
|
@@ -6,13 +6,12 @@ from typing_extensions import Annotated
|
|
6
6
|
|
7
7
|
from classiq.interface.chemistry.fermionic_operator import SummedFermionicOperator
|
8
8
|
from classiq.interface.chemistry.molecule import Molecule
|
9
|
+
from classiq.interface.enum_utils import StrEnum
|
10
|
+
from classiq.interface.exceptions import ClassiqValueError
|
9
11
|
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
10
12
|
HashablePydanticBaseModel,
|
11
13
|
)
|
12
14
|
|
13
|
-
from classiq._internals.enum_utils import StrEnum
|
14
|
-
from classiq.exceptions import ClassiqValueError
|
15
|
-
|
16
15
|
"""
|
17
16
|
The correct type hint is:
|
18
17
|
NumSpinUpParticles = pydantic.NonNegativeInt
|
@@ -3,13 +3,12 @@ from typing import List, Literal, Union
|
|
3
3
|
import pydantic
|
4
4
|
|
5
5
|
from classiq.interface.chemistry.elements import ELEMENTS
|
6
|
+
from classiq.interface.exceptions import ClassiqValueError
|
6
7
|
from classiq.interface.helpers.custom_pydantic_types import AtomType
|
7
8
|
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
8
9
|
HashablePydanticBaseModel,
|
9
10
|
)
|
10
11
|
|
11
|
-
from classiq.exceptions import ClassiqValueError
|
12
|
-
|
13
12
|
|
14
13
|
class Atom(HashablePydanticBaseModel):
|
15
14
|
symbol: Literal[tuple(ELEMENTS)] = pydantic.Field(description="The atom symbol") # type: ignore[valid-type]
|
@@ -1,6 +1,5 @@
|
|
1
1
|
from functools import reduce
|
2
2
|
from typing import (
|
3
|
-
TYPE_CHECKING,
|
4
3
|
Any,
|
5
4
|
Collection,
|
6
5
|
Dict,
|
@@ -16,12 +15,14 @@ import pydantic
|
|
16
15
|
import sympy
|
17
16
|
from more_itertools import all_equal
|
18
17
|
|
18
|
+
from classiq.interface.exceptions import ClassiqValueError
|
19
19
|
from classiq.interface.generator.function_params import validate_expression_str
|
20
20
|
from classiq.interface.generator.parameters import (
|
21
21
|
ParameterComplexType,
|
22
22
|
ParameterType,
|
23
23
|
PydanticParameterComplexType,
|
24
24
|
)
|
25
|
+
from classiq.interface.generator.types.builtin_enum_declarations import Pauli
|
25
26
|
from classiq.interface.helpers.custom_pydantic_types import (
|
26
27
|
PydanticPauliList,
|
27
28
|
PydanticPauliMonomial,
|
@@ -32,11 +33,6 @@ from classiq.interface.helpers.hashable_pydantic_base_model import (
|
|
32
33
|
)
|
33
34
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
34
35
|
|
35
|
-
from classiq.exceptions import ClassiqValueError
|
36
|
-
|
37
|
-
if TYPE_CHECKING:
|
38
|
-
from classiq.qmod.builtins.enums import Pauli
|
39
|
-
|
40
36
|
|
41
37
|
class PauliOperator(HashablePydanticBaseModel, VersionedModel):
|
42
38
|
"""
|
@@ -140,8 +136,12 @@ class PauliOperator(HashablePydanticBaseModel, VersionedModel):
|
|
140
136
|
def num_qubits(self) -> int:
|
141
137
|
return len(self.pauli_list[0][0])
|
142
138
|
|
139
|
+
@property
|
140
|
+
def all_coefficients_numeric(self) -> bool:
|
141
|
+
return all(isinstance(summand[1], complex) for summand in self.pauli_list)
|
142
|
+
|
143
143
|
def to_matrix(self) -> np.ndarray:
|
144
|
-
if not
|
144
|
+
if not self.all_coefficients_numeric:
|
145
145
|
raise ClassiqValueError(
|
146
146
|
"Supporting only Hamiltonian with numeric coefficients."
|
147
147
|
)
|
@@ -478,9 +478,7 @@ def validate_operator_has_no_complex_coefficients(
|
|
478
478
|
return pauli_operator
|
479
479
|
|
480
480
|
|
481
|
-
def pauli_integers_to_str(paulis: List[
|
482
|
-
from classiq.qmod.builtins.enums import Pauli
|
483
|
-
|
481
|
+
def pauli_integers_to_str(paulis: List[Pauli]) -> str:
|
484
482
|
return "".join([Pauli(pauli).name for pauli in paulis])
|
485
483
|
|
486
484
|
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
from typing import Dict, Optional, Union
|
2
|
+
from uuid import UUID
|
3
|
+
|
4
|
+
from pydantic import BaseModel, Field
|
5
|
+
|
6
|
+
from classiq.interface.ide.visual_model import OperationLevel
|
7
|
+
|
8
|
+
|
9
|
+
class FunctionDebugInfo(BaseModel):
|
10
|
+
name: str
|
11
|
+
parameters: Dict[str, Union[int, float, None]]
|
12
|
+
level: OperationLevel
|
13
|
+
is_allocate_or_free: bool = Field(default=False)
|
14
|
+
|
15
|
+
|
16
|
+
class DebugInfoCollection(BaseModel):
|
17
|
+
# Pydantic only started supporting UUID as keys in Pydantic V2
|
18
|
+
# See https://github.com/pydantic/pydantic/issues/2096#issuecomment-814860206
|
19
|
+
# For now, we use strings as keys in the raw data and use UUID in the wrapper logic
|
20
|
+
data: Dict[str, FunctionDebugInfo] = Field(default_factory=dict)
|
21
|
+
|
22
|
+
def __setitem__(self, key: UUID, value: FunctionDebugInfo) -> None:
|
23
|
+
self.data[str(key)] = value
|
24
|
+
|
25
|
+
def get(self, key: UUID) -> Optional[FunctionDebugInfo]:
|
26
|
+
return self.data.get(str(key))
|
27
|
+
|
28
|
+
def __getitem__(self, key: UUID) -> FunctionDebugInfo:
|
29
|
+
return self.data[str(key)]
|
30
|
+
|
31
|
+
def __contains__(self, key: UUID) -> bool:
|
32
|
+
return str(key) in self.data
|
@@ -4,8 +4,8 @@ from typing import Any, Dict, List, Optional
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic import validator
|
6
6
|
|
7
|
-
from classiq.
|
8
|
-
from classiq.exceptions import ClassiqValueError
|
7
|
+
from classiq.interface.enum_utils import StrEnum
|
8
|
+
from classiq.interface.exceptions import ClassiqValueError
|
9
9
|
|
10
10
|
|
11
11
|
class Granularity(StrEnum):
|