classiq 0.32.1__py3-none-any.whl → 0.34.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- classiq/__init__.py +2 -1
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +1 -1
- classiq/_internals/api_wrapper.py +34 -23
- classiq/_internals/jobs.py +41 -14
- classiq/analyzer/__init__.py +3 -1
- classiq/applications/__init__.py +3 -1
- classiq/applications/benchmarking/__init__.py +3 -1
- classiq/applications/chemistry/__init__.py +3 -1
- classiq/applications/combinatorial_optimization/__init__.py +3 -1
- classiq/applications/combinatorial_optimization/examples/__init__.py +3 -1
- classiq/applications/finance/__init__.py +3 -1
- classiq/applications/qnn/__init__.py +3 -1
- classiq/applications/qnn/datasets/__init__.py +3 -1
- classiq/applications/qsvm/qsvm.py +1 -1
- classiq/applications_model_constructors/grover_model_constructor.py +25 -8
- classiq/builtin_functions/__init__.py +3 -1
- classiq/execution/__init__.py +3 -1
- classiq/execution/jobs.py +57 -20
- classiq/executor.py +4 -11
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +1 -1
- classiq/interface/backend/backend_preferences.py +17 -0
- classiq/interface/backend/pydantic_backend.py +8 -0
- classiq/interface/backend/quantum_backend_providers.py +15 -1
- classiq/interface/chemistry/ground_state_problem.py +1 -1
- classiq/interface/chemistry/operator.py +198 -0
- classiq/interface/executor/execution_request.py +5 -12
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +4 -1
- classiq/interface/generator/functions/__init__.py +3 -1
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/__init__.py +0 -1
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/atomic_quantum_functions.py +39 -39
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/std_lib_functions.py +251 -87
- classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +5 -54
- classiq/interface/generator/generated_circuit.py +14 -43
- classiq/interface/generator/generated_circuit_data.py +26 -34
- classiq/interface/generator/model/preferences/preferences.py +3 -3
- classiq/interface/generator/partitioned_register.py +1 -1
- classiq/interface/generator/quantum_function_call.py +1 -1
- classiq/interface/generator/validations/validator_functions.py +4 -2
- classiq/interface/hardware.py +3 -2
- classiq/interface/ide/show.py +1 -14
- classiq/interface/model/bind_operation.py +20 -0
- classiq/interface/model/handle_binding.py +8 -0
- classiq/interface/model/native_function_definition.py +15 -5
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +8 -3
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +9 -4
- classiq/interface/model/quantum_expressions/quantum_expression.py +10 -5
- classiq/interface/model/quantum_function_call.py +24 -347
- classiq/interface/model/quantum_function_declaration.py +7 -11
- classiq/interface/model/quantum_statement.py +13 -7
- classiq/interface/model/validations/handle_validation_base.py +1 -2
- classiq/interface/model/validations/handles_validator.py +34 -8
- classiq/interface/model/variable_declaration_statement.py +8 -0
- classiq/interface/server/routes.py +11 -16
- classiq/model/__init__.py +3 -1
- classiq/model/function_handler.py +1 -1
- classiq/model/function_handler.pyi +88 -88
- classiq/qmod/declaration_inferrer.py +37 -18
- classiq/qmod/model_state_container.py +6 -3
- classiq/qmod/qmod_builtins.py +892 -4
- classiq/qmod/qmod_parameter.py +24 -8
- classiq/qmod/qmod_variable.py +2 -1
- classiq/qmod/quantum_expandable.py +6 -2
- classiq/qmod/quantum_function.py +11 -10
- classiq/quantum_functions/quantum_function.py +4 -1
- {classiq-0.32.1.dist-info → classiq-0.34.0.dist-info}/METADATA +1 -1
- {classiq-0.32.1.dist-info → classiq-0.34.0.dist-info}/RECORD +69 -72
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/apps_lib_functions.py +0 -262
- classiq/interface/model/clients/__init__.py +0 -0
- classiq/interface/model/clients/qmod/__init__.py +0 -0
- classiq/interface/model/clients/qmod/qmod_builtins.py +0 -908
- classiq/interface/model/semantics.py +0 -15
- {classiq-0.32.1.dist-info → classiq-0.34.0.dist-info}/WHEEL +0 -0
@@ -66,7 +66,7 @@ class TranspilationOption(StrEnum):
|
|
66
66
|
LIGHT = "light"
|
67
67
|
MEDIUM = "medium"
|
68
68
|
|
69
|
-
def __bool__(self):
|
69
|
+
def __bool__(self) -> bool:
|
70
70
|
return self != TranspilationOption.NONE
|
71
71
|
|
72
72
|
|
@@ -89,9 +89,9 @@ class Preferences(pydantic.BaseModel, extra=pydantic.Extra.forbid):
|
|
89
89
|
description="Custom hardware settings which will be used during optimization. "
|
90
90
|
"This field is ignored if backend preferences are given.",
|
91
91
|
)
|
92
|
-
|
92
|
+
debug_mode: bool = pydantic.Field(
|
93
93
|
default=True,
|
94
|
-
description="
|
94
|
+
description="Add debug information to the synthesized result. "
|
95
95
|
"Setting this option to False can potentially speed up the synthesis, and is "
|
96
96
|
"recommended for executing iterative algorithms.",
|
97
97
|
)
|
@@ -44,7 +44,7 @@ class PartitionedRegister:
|
|
44
44
|
# Special partition containing qubits from [0..num_qubits) not in any other
|
45
45
|
# partition. May contain no qubits.
|
46
46
|
@property
|
47
|
-
def leftover_partition(self):
|
47
|
+
def leftover_partition(self) -> "RegisterPartition":
|
48
48
|
return RegisterPartition(self, _index=None)
|
49
49
|
|
50
50
|
@property
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Iterable, List, Sized, Tuple, TypeVar
|
1
|
+
from typing import Iterable, List, Sequence, Sized, Tuple, TypeVar
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
|
@@ -32,7 +32,9 @@ def validate_amplitudes(amp: Amplitude) -> Amplitude:
|
|
32
32
|
return amp
|
33
33
|
|
34
34
|
|
35
|
-
def validate_probabilities(
|
35
|
+
def validate_probabilities(
|
36
|
+
cls: type, pmf: Sequence[PydanticProbabilityFloat]
|
37
|
+
) -> Sequence[PydanticProbabilityFloat]:
|
36
38
|
if not is_probabilities_sum_to_one(pmf):
|
37
39
|
raise ValueError(NOT_SUM_TO_ONE_ERROR)
|
38
40
|
if not _is_power_of_two(pmf):
|
classiq/interface/hardware.py
CHANGED
@@ -13,6 +13,7 @@ class Provider(StrEnum):
|
|
13
13
|
IONQ = "IonQ"
|
14
14
|
CLASSIQ = "Classiq"
|
15
15
|
GOOGLE = "Google"
|
16
|
+
ALICE_AND_BOB = "Alice and Bob"
|
16
17
|
|
17
18
|
@property
|
18
19
|
def id(self):
|
@@ -27,7 +28,7 @@ class AvailabilityStatus(StrEnum):
|
|
27
28
|
UNAVAILABLE = "unavailable"
|
28
29
|
|
29
30
|
@property
|
30
|
-
def is_available(self):
|
31
|
+
def is_available(self) -> bool:
|
31
32
|
return self == self.AVAILABLE
|
32
33
|
|
33
34
|
|
@@ -37,7 +38,7 @@ class DeviceType(StrEnum):
|
|
37
38
|
STATEVECTOR = "state_vector_simulator"
|
38
39
|
|
39
40
|
@property
|
40
|
-
def is_simulator(self):
|
41
|
+
def is_simulator(self) -> bool:
|
41
42
|
return self != self.HARDWARE
|
42
43
|
|
43
44
|
|
classiq/interface/ide/show.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
import re
|
2
|
-
from typing import Union
|
3
2
|
|
4
3
|
import pydantic
|
5
4
|
|
6
5
|
from classiq.interface.analyzer.result import QasmCode
|
7
|
-
from classiq.interface.generator.generated_circuit import ExecutionCircuit
|
8
6
|
|
9
7
|
from classiq import GeneratedCircuit
|
10
8
|
from classiq._internals.api_wrapper import ApiWrapper
|
@@ -26,22 +24,11 @@ qasm_show_interactive = syncify_function(qasm_show_interactive_async)
|
|
26
24
|
CANT_PARSE_QUANTUM_PROGRAM_MSG = (
|
27
25
|
"Can not parse quantum_program into GeneratedCircuit, \n"
|
28
26
|
)
|
29
|
-
CANT_SHOW_EXECUTION_CIRCUIT_MSG = (
|
30
|
-
"It looks like the flag `support_circuit_visualization` in the model preferences "
|
31
|
-
"has been turned off. \n"
|
32
|
-
"The resulting circuit does not support visualization. \n"
|
33
|
-
"Make sure to set the flag to True, the default setting, and try again."
|
34
|
-
)
|
35
|
-
_Circuit = Union[GeneratedCircuit, ExecutionCircuit]
|
36
27
|
|
37
28
|
|
38
29
|
def show(quantum_program: SerializedQuantumProgram) -> None:
|
39
30
|
try:
|
40
31
|
circuit = GeneratedCircuit.parse_raw(quantum_program)
|
41
32
|
except pydantic.error_wrappers.ValidationError as exc:
|
42
|
-
|
43
|
-
ExecutionCircuit.parse_raw(quantum_program)
|
44
|
-
raise ClassiqValueError(CANT_SHOW_EXECUTION_CIRCUIT_MSG) from None
|
45
|
-
except pydantic.error_wrappers.ValidationError:
|
46
|
-
raise ClassiqValueError(CANT_PARSE_QUANTUM_PROGRAM_MSG) from exc
|
33
|
+
raise ClassiqValueError(CANT_PARSE_QUANTUM_PROGRAM_MSG) from exc
|
47
34
|
circuit.show() # type: ignore[attr-defined]
|
@@ -0,0 +1,20 @@
|
|
1
|
+
from typing import Mapping
|
2
|
+
|
3
|
+
from classiq.interface.model.handle_binding import HandleBinding
|
4
|
+
from classiq.interface.model.quantum_statement import QuantumOperation
|
5
|
+
|
6
|
+
BIND_INPUT_NAME = "bind_input"
|
7
|
+
BIND_OUTPUT_NAME = "bind_output"
|
8
|
+
|
9
|
+
|
10
|
+
class BindOperation(QuantumOperation):
|
11
|
+
in_handle: HandleBinding
|
12
|
+
out_handle: HandleBinding
|
13
|
+
|
14
|
+
@property
|
15
|
+
def wiring_inputs(self) -> Mapping[str, HandleBinding]:
|
16
|
+
return {BIND_INPUT_NAME: self.in_handle}
|
17
|
+
|
18
|
+
@property
|
19
|
+
def wiring_outputs(self) -> Mapping[str, HandleBinding]:
|
20
|
+
return {BIND_OUTPUT_NAME: self.out_handle}
|
@@ -11,6 +11,14 @@ class HandleBinding(BaseModel):
|
|
11
11
|
extra = Extra.forbid
|
12
12
|
|
13
13
|
|
14
|
+
class SubscriptHandleBinding(HandleBinding):
|
15
|
+
index: Expression
|
16
|
+
|
17
|
+
class Config:
|
18
|
+
frozen = True
|
19
|
+
extra = Extra.forbid
|
20
|
+
|
21
|
+
|
14
22
|
class SlicedHandleBinding(HandleBinding):
|
15
23
|
start: Expression
|
16
24
|
end: Expression
|
@@ -2,8 +2,8 @@ from typing import Any, Dict, List, Optional, Union
|
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
-
from classiq.interface.generator.function_params import IOName
|
6
5
|
from classiq.interface.generator.parameters import ParameterFloatType, ParameterMap
|
6
|
+
from classiq.interface.model.bind_operation import BindOperation
|
7
7
|
from classiq.interface.model.local_variable_declaration import LocalVariableDeclaration
|
8
8
|
from classiq.interface.model.port_declaration import PortDeclaration
|
9
9
|
from classiq.interface.model.quantum_expressions.amplitude_loading_operation import (
|
@@ -17,11 +17,18 @@ from classiq.interface.model.quantum_function_declaration import (
|
|
17
17
|
QuantumFunctionDeclaration,
|
18
18
|
)
|
19
19
|
from classiq.interface.model.validations.handles_validator import HandleValidator
|
20
|
+
from classiq.interface.model.variable_declaration_statement import (
|
21
|
+
VariableDeclarationStatement,
|
22
|
+
)
|
20
23
|
|
21
24
|
from classiq.exceptions import ClassiqValueError
|
22
25
|
|
23
26
|
ConcreteQuantumStatement = Union[
|
24
|
-
QuantumFunctionCall,
|
27
|
+
QuantumFunctionCall,
|
28
|
+
ArithmeticOperation,
|
29
|
+
AmplitudeLoadingOperation,
|
30
|
+
VariableDeclarationStatement,
|
31
|
+
BindOperation,
|
25
32
|
]
|
26
33
|
|
27
34
|
|
@@ -49,8 +56,11 @@ class NativeFunctionDefinition(QuantumFunctionDeclaration):
|
|
49
56
|
def validate_body(self) -> None:
|
50
57
|
handle_validator = HandleValidator(self.port_declarations, self.local_handles)
|
51
58
|
|
52
|
-
for
|
53
|
-
|
59
|
+
for statement in self.body:
|
60
|
+
if isinstance(statement, VariableDeclarationStatement):
|
61
|
+
handle_validator.handle_variable_declaration(statement)
|
62
|
+
else:
|
63
|
+
handle_validator.handle_call(statement)
|
54
64
|
|
55
65
|
handle_validator.report_errored_handles(ClassiqValueError)
|
56
66
|
|
@@ -64,7 +74,7 @@ class NativeFunctionDefinition(QuantumFunctionDeclaration):
|
|
64
74
|
def validate_local_handles(
|
65
75
|
cls, local_handles: List[LocalVariableDeclaration], values: Dict[str, Any]
|
66
76
|
) -> List[LocalVariableDeclaration]:
|
67
|
-
ports: Optional[Dict[
|
77
|
+
ports: Optional[Dict[str, PortDeclaration]] = values.get("port_declarations")
|
68
78
|
if ports is None:
|
69
79
|
return local_handles
|
70
80
|
|
@@ -6,8 +6,11 @@ from classiq.interface.generator.amplitude_loading import (
|
|
6
6
|
AMPLITUDE_IO_NAME,
|
7
7
|
TARGET_OUTPUT_NAME,
|
8
8
|
)
|
9
|
-
from classiq.interface.
|
10
|
-
|
9
|
+
from classiq.interface.model.handle_binding import (
|
10
|
+
HandleBinding,
|
11
|
+
SlicedHandleBinding,
|
12
|
+
SubscriptHandleBinding,
|
13
|
+
)
|
11
14
|
from classiq.interface.model.quantum_expressions.quantum_expression import (
|
12
15
|
QuantumExpressionOperation,
|
13
16
|
)
|
@@ -34,7 +37,9 @@ class AmplitudeLoadingOperation(QuantumExpressionOperation):
|
|
34
37
|
@property
|
35
38
|
def wiring_inouts(
|
36
39
|
self,
|
37
|
-
) -> Mapping[
|
40
|
+
) -> Mapping[
|
41
|
+
str, Union[SlicedHandleBinding, SubscriptHandleBinding, HandleBinding]
|
42
|
+
]:
|
38
43
|
assert len(self.var_handles) > 0
|
39
44
|
return {AMPLITUDE_IO_NAME: self.var_handles[0]}
|
40
45
|
|
@@ -6,8 +6,11 @@ from classiq.interface.generator.arith.arithmetic import (
|
|
6
6
|
ARITHMETIC_EXPRESSION_RESULT_NAME,
|
7
7
|
compute_arithmetic_result_type,
|
8
8
|
)
|
9
|
-
from classiq.interface.
|
10
|
-
|
9
|
+
from classiq.interface.model.handle_binding import (
|
10
|
+
HandleBinding,
|
11
|
+
SlicedHandleBinding,
|
12
|
+
SubscriptHandleBinding,
|
13
|
+
)
|
11
14
|
from classiq.interface.model.quantum_expressions.quantum_expression import (
|
12
15
|
QuantumExpressionOperation,
|
13
16
|
)
|
@@ -26,14 +29,16 @@ class ArithmeticOperation(QuantumExpressionOperation):
|
|
26
29
|
@property
|
27
30
|
def wiring_inouts(
|
28
31
|
self,
|
29
|
-
) -> Mapping[
|
32
|
+
) -> Mapping[
|
33
|
+
str, Union[SlicedHandleBinding, SubscriptHandleBinding, HandleBinding]
|
34
|
+
]:
|
30
35
|
inouts = dict(super().wiring_inouts)
|
31
36
|
if self.inplace_result:
|
32
37
|
inouts[self.result_name()] = self.result_var
|
33
38
|
return inouts
|
34
39
|
|
35
40
|
@property
|
36
|
-
def wiring_outputs(self) -> Mapping[
|
41
|
+
def wiring_outputs(self) -> Mapping[str, HandleBinding]:
|
37
42
|
if self.inplace_result:
|
38
43
|
return {}
|
39
44
|
return super().wiring_outputs
|
@@ -7,9 +7,12 @@ import pydantic
|
|
7
7
|
from classiq.interface.generator.expressions.sympy_supported_expressions import (
|
8
8
|
SYMPY_SUPPORTED_EXPRESSIONS,
|
9
9
|
)
|
10
|
-
from classiq.interface.generator.function_params import IOName
|
11
10
|
from classiq.interface.helpers.pydantic_model_helpers import nameables_to_dict
|
12
|
-
from classiq.interface.model.handle_binding import
|
11
|
+
from classiq.interface.model.handle_binding import (
|
12
|
+
HandleBinding,
|
13
|
+
SlicedHandleBinding,
|
14
|
+
SubscriptHandleBinding,
|
15
|
+
)
|
13
16
|
from classiq.interface.model.quantum_statement import QuantumOperation
|
14
17
|
from classiq.interface.model.quantum_type import QuantumType
|
15
18
|
|
@@ -18,7 +21,7 @@ class VarRefCollector(ast.NodeVisitor):
|
|
18
21
|
def __init__(self) -> None:
|
19
22
|
self.var_names: Set[str] = set()
|
20
23
|
|
21
|
-
def generic_visit(self, node):
|
24
|
+
def generic_visit(self, node: ast.AST) -> None:
|
22
25
|
if isinstance(node, ast.Name) and node.id not in set(
|
23
26
|
SYMPY_SUPPORTED_EXPRESSIONS
|
24
27
|
):
|
@@ -57,11 +60,13 @@ class QuantumExpressionOperation(QuantumOperation):
|
|
57
60
|
@property
|
58
61
|
def wiring_inouts(
|
59
62
|
self,
|
60
|
-
) -> Mapping[
|
63
|
+
) -> Mapping[
|
64
|
+
str, Union[SlicedHandleBinding, SubscriptHandleBinding, HandleBinding]
|
65
|
+
]:
|
61
66
|
return nameables_to_dict(self.var_handles)
|
62
67
|
|
63
68
|
@property
|
64
|
-
def wiring_outputs(self) -> Mapping[
|
69
|
+
def wiring_outputs(self) -> Mapping[str, HandleBinding]:
|
65
70
|
return {self.result_name(): self.result_var}
|
66
71
|
|
67
72
|
@property
|