classiq 0.62.0__py3-none-any.whl → 0.63.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 +3 -0
- classiq/_internals/api_wrapper.py +6 -26
- classiq/_internals/client.py +1 -9
- classiq/applications/chemistry/chemistry_model_constructor.py +1 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +26 -8
- classiq/applications/combinatorial_helpers/optimization_model.py +5 -1
- classiq/applications/combinatorial_helpers/pyomo_utils.py +106 -27
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +1 -1
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +4 -2
- classiq/applications/grover/grover_model_constructor.py +1 -1
- classiq/applications/libraries/qmci_library.py +2 -1
- classiq/execution/execution_session.py +66 -96
- classiq/execution/jobs.py +3 -9
- classiq/interface/_version.py +1 -1
- classiq/interface/backend/backend_preferences.py +8 -5
- classiq/interface/backend/pydantic_backend.py +1 -1
- classiq/interface/chemistry/operator.py +0 -204
- classiq/interface/execution/primitives.py +1 -0
- classiq/interface/generator/compiler_keywords.py +4 -0
- classiq/interface/generator/functions/type_name.py +6 -0
- classiq/interface/generator/generated_circuit_data.py +22 -7
- classiq/interface/generator/model/model.py +3 -0
- classiq/interface/generator/model/preferences/preferences.py +13 -0
- classiq/interface/generator/quantum_function_call.py +4 -2
- classiq/interface/model/handle_binding.py +50 -5
- classiq/interface/model/quantum_type.py +16 -0
- classiq/interface/server/routes.py +1 -3
- classiq/model_expansions/capturing/captured_vars.py +102 -19
- classiq/model_expansions/closure.py +19 -56
- classiq/model_expansions/function_builder.py +13 -8
- classiq/model_expansions/generative_functions.py +15 -1
- classiq/model_expansions/interpreter.py +94 -32
- classiq/model_expansions/model_tables.py +4 -0
- classiq/model_expansions/quantum_operations/call_emitter.py +61 -2
- classiq/model_expansions/quantum_operations/classicalif.py +1 -1
- classiq/model_expansions/quantum_operations/control.py +3 -10
- classiq/model_expansions/quantum_operations/emitter.py +1 -1
- classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +1 -2
- classiq/model_expansions/quantum_operations/repeat.py +4 -3
- classiq/model_expansions/scope.py +7 -1
- classiq/model_expansions/scope_initialization.py +34 -25
- classiq/model_expansions/transformers/var_splitter.py +57 -7
- classiq/open_library/__init__.py +4 -0
- classiq/open_library/functions/__init__.py +130 -0
- classiq/{qmod/builtins → open_library}/functions/amplitude_estimation.py +2 -2
- classiq/{qmod/builtins → open_library}/functions/discrete_sine_cosine_transform.py +6 -4
- classiq/{qmod/builtins → open_library}/functions/grover.py +2 -2
- classiq/{qmod/builtins → open_library}/functions/linear_pauli_rotation.py +1 -1
- classiq/{qmod/builtins → open_library}/functions/modular_exponentiation.py +2 -2
- classiq/{qmod/builtins → open_library}/functions/qpe.py +2 -2
- classiq/{qmod/builtins → open_library}/functions/state_preparation.py +6 -149
- classiq/{qmod/builtins → open_library}/functions/swap_test.py +1 -1
- classiq/open_library/functions/utility_functions.py +81 -0
- classiq/{qmod/builtins → open_library}/functions/variational.py +1 -1
- classiq/qmod/builtins/functions/__init__.py +4 -130
- classiq/qmod/builtins/functions/allocation.py +150 -0
- classiq/qmod/builtins/functions/arithmetic.py +0 -34
- classiq/qmod/builtins/functions/operators.py +0 -6
- classiq/qmod/create_model_function.py +8 -162
- classiq/qmod/generative.py +0 -16
- classiq/qmod/model_state_container.py +7 -0
- classiq/qmod/native/pretty_printer.py +10 -11
- classiq/qmod/pretty_print/pretty_printer.py +1 -1
- classiq/qmod/qfunc.py +11 -12
- classiq/qmod/qmod_variable.py +1 -3
- classiq/qmod/quantum_expandable.py +21 -0
- classiq/qmod/quantum_function.py +65 -3
- {classiq-0.62.0.dist-info → classiq-0.63.0.dist-info}/METADATA +1 -1
- {classiq-0.62.0.dist-info → classiq-0.63.0.dist-info}/RECORD +74 -71
- classiq/qmod/builtins/functions/utility_functions.py +0 -43
- /classiq/{qmod/builtins → open_library}/functions/hea.py +0 -0
- /classiq/{qmod/builtins → open_library}/functions/qaoa_penalty.py +0 -0
- /classiq/{qmod/builtins → open_library}/functions/qft_functions.py +0 -0
- /classiq/{qmod/builtins → open_library}/functions/qsvt.py +0 -0
- {classiq-0.62.0.dist-info → classiq-0.63.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
from .amplitude_estimation import *
|
2
|
+
from .discrete_sine_cosine_transform import *
|
3
|
+
from .discrete_sine_cosine_transform import _qct_d_operator, _qct_pi_operator
|
4
|
+
from .grover import *
|
5
|
+
from .hea import *
|
6
|
+
from .linear_pauli_rotation import *
|
7
|
+
from .linear_pauli_rotation import _single_pauli
|
8
|
+
from .modular_exponentiation import *
|
9
|
+
from .modular_exponentiation import _check_msb, _ctrl_x
|
10
|
+
from .qaoa_penalty import *
|
11
|
+
from .qft_functions import *
|
12
|
+
from .qpe import *
|
13
|
+
from .qsvt import *
|
14
|
+
from .state_preparation import *
|
15
|
+
from .state_preparation import _prepare_uniform_trimmed_state_step
|
16
|
+
from .swap_test import *
|
17
|
+
from .utility_functions import *
|
18
|
+
from .variational import *
|
19
|
+
|
20
|
+
OPEN_LIBRARY_FUNCTIONS = [
|
21
|
+
qpe_flexible,
|
22
|
+
qpe,
|
23
|
+
_single_pauli,
|
24
|
+
linear_pauli_rotations,
|
25
|
+
amplitude_estimation,
|
26
|
+
phase_oracle,
|
27
|
+
reflect_about_zero,
|
28
|
+
grover_diffuser,
|
29
|
+
grover_operator,
|
30
|
+
grover_search,
|
31
|
+
hadamard_transform,
|
32
|
+
apply_to_all,
|
33
|
+
qft_no_swap,
|
34
|
+
qft_space_add_const,
|
35
|
+
cc_modular_add,
|
36
|
+
c_modular_multiply,
|
37
|
+
multiswap,
|
38
|
+
inplace_c_modular_multiply,
|
39
|
+
modular_exp,
|
40
|
+
qsvt_step,
|
41
|
+
qsvt,
|
42
|
+
projector_controlled_double_phase,
|
43
|
+
projector_controlled_phase,
|
44
|
+
qsvt_inversion,
|
45
|
+
qsvt_lcu,
|
46
|
+
qsvt_lcu_step,
|
47
|
+
allocate_num,
|
48
|
+
qaoa_mixer_layer,
|
49
|
+
qaoa_cost_layer,
|
50
|
+
qaoa_layer,
|
51
|
+
qaoa_init,
|
52
|
+
qaoa_penalty,
|
53
|
+
full_hea,
|
54
|
+
swap_test,
|
55
|
+
prepare_uniform_trimmed_state,
|
56
|
+
prepare_uniform_interval_state,
|
57
|
+
prepare_ghz_state,
|
58
|
+
prepare_exponential_state,
|
59
|
+
prepare_bell_state,
|
60
|
+
inplace_prepare_int,
|
61
|
+
prepare_int,
|
62
|
+
switch,
|
63
|
+
qct_qst_type1,
|
64
|
+
qct_qst_type2,
|
65
|
+
qct_type2,
|
66
|
+
qst_type2,
|
67
|
+
modular_increment,
|
68
|
+
qft,
|
69
|
+
_ctrl_x,
|
70
|
+
_prepare_uniform_trimmed_state_step,
|
71
|
+
_qct_d_operator,
|
72
|
+
_qct_pi_operator,
|
73
|
+
_check_msb,
|
74
|
+
encode_in_angle,
|
75
|
+
encode_on_bloch,
|
76
|
+
]
|
77
|
+
|
78
|
+
__all__ = [
|
79
|
+
"_single_pauli",
|
80
|
+
"allocate_num",
|
81
|
+
"amplitude_estimation",
|
82
|
+
"apply_to_all",
|
83
|
+
"c_modular_multiply",
|
84
|
+
"cc_modular_add",
|
85
|
+
"encode_in_angle",
|
86
|
+
"encode_on_bloch",
|
87
|
+
"full_hea",
|
88
|
+
"grover_diffuser",
|
89
|
+
"grover_operator",
|
90
|
+
"grover_search",
|
91
|
+
"hadamard_transform",
|
92
|
+
"inplace_c_modular_multiply",
|
93
|
+
"inplace_prepare_int",
|
94
|
+
"linear_pauli_rotations",
|
95
|
+
"modular_exp",
|
96
|
+
"modular_increment",
|
97
|
+
"multiswap",
|
98
|
+
"phase_oracle",
|
99
|
+
"prepare_bell_state",
|
100
|
+
"prepare_exponential_state",
|
101
|
+
"prepare_ghz_state",
|
102
|
+
"prepare_int",
|
103
|
+
"prepare_uniform_interval_state",
|
104
|
+
"prepare_uniform_trimmed_state",
|
105
|
+
"projector_controlled_double_phase",
|
106
|
+
"projector_controlled_phase",
|
107
|
+
"qaoa_cost_layer",
|
108
|
+
"qaoa_init",
|
109
|
+
"qaoa_layer",
|
110
|
+
"qaoa_mixer_layer",
|
111
|
+
"qaoa_penalty",
|
112
|
+
"qct_qst_type1",
|
113
|
+
"qct_qst_type2",
|
114
|
+
"qct_type2",
|
115
|
+
"qft",
|
116
|
+
"qft_no_swap",
|
117
|
+
"qft_space_add_const",
|
118
|
+
"qpe",
|
119
|
+
"qpe_flexible",
|
120
|
+
"qst_type2",
|
121
|
+
"qsvt",
|
122
|
+
"qsvt_inversion",
|
123
|
+
"qsvt_lcu",
|
124
|
+
"qsvt_lcu_step",
|
125
|
+
"qsvt_step",
|
126
|
+
"reflect_about_zero",
|
127
|
+
"suzuki_trotter",
|
128
|
+
"swap_test",
|
129
|
+
"switch",
|
130
|
+
]
|
@@ -1,5 +1,5 @@
|
|
1
|
-
from classiq.
|
2
|
-
from classiq.
|
1
|
+
from classiq.open_library.functions.grover import grover_operator
|
2
|
+
from classiq.open_library.functions.qpe import qpe
|
3
3
|
from classiq.qmod.qfunc import qfunc
|
4
4
|
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
5
5
|
from classiq.qmod.quantum_callable import QCallable
|
@@ -1,8 +1,10 @@
|
|
1
|
-
from classiq.
|
2
|
-
from classiq.
|
1
|
+
from classiq.open_library.functions.qft_functions import qft
|
2
|
+
from classiq.open_library.functions.utility_functions import (
|
3
|
+
apply_to_all,
|
4
|
+
modular_increment,
|
5
|
+
)
|
6
|
+
from classiq.qmod.builtins.functions import allocate
|
3
7
|
from classiq.qmod.builtins.functions.standard_gates import PHASE, H, S, X, Z
|
4
|
-
from classiq.qmod.builtins.functions.state_preparation import allocate
|
5
|
-
from classiq.qmod.builtins.functions.utility_functions import apply_to_all
|
6
8
|
from classiq.qmod.builtins.operations import bind, control, invert, repeat, within_apply
|
7
9
|
from classiq.qmod.qfunc import qfunc
|
8
10
|
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
@@ -1,6 +1,6 @@
|
|
1
|
+
from classiq.open_library.functions.utility_functions import hadamard_transform
|
2
|
+
from classiq.qmod.builtins.functions import allocate
|
1
3
|
from classiq.qmod.builtins.functions.standard_gates import H, U, X
|
2
|
-
from classiq.qmod.builtins.functions.state_preparation import allocate
|
3
|
-
from classiq.qmod.builtins.functions.utility_functions import hadamard_transform
|
4
4
|
from classiq.qmod.builtins.operations import (
|
5
5
|
bind,
|
6
6
|
control,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from typing import Annotated
|
2
2
|
|
3
|
+
from classiq.open_library.functions.utility_functions import switch
|
3
4
|
from classiq.qmod.builtins.enums import Pauli
|
4
|
-
from classiq.qmod.builtins.functions.operators import switch
|
5
5
|
from classiq.qmod.builtins.functions.standard_gates import IDENTITY, RX, RY, RZ
|
6
6
|
from classiq.qmod.builtins.operations import control, repeat
|
7
7
|
from classiq.qmod.qfunc import qfunc
|
@@ -1,7 +1,7 @@
|
|
1
|
+
from classiq.open_library.functions.qft_functions import qft, qft_no_swap
|
1
2
|
from classiq.qmod.builtins.classical_functions import qft_const_adder_phase
|
2
|
-
from classiq.qmod.builtins.functions
|
3
|
+
from classiq.qmod.builtins.functions import allocate
|
3
4
|
from classiq.qmod.builtins.functions.standard_gates import PHASE, SWAP, X
|
4
|
-
from classiq.qmod.builtins.functions.state_preparation import allocate
|
5
5
|
from classiq.qmod.builtins.operations import bind, control, invert, repeat, within_apply
|
6
6
|
from classiq.qmod.cparam import CInt
|
7
7
|
from classiq.qmod.qfunc import qfunc
|
@@ -1,6 +1,6 @@
|
|
1
|
-
from classiq.
|
1
|
+
from classiq.open_library.functions.qft_functions import qft
|
2
|
+
from classiq.open_library.functions.utility_functions import apply_to_all
|
2
3
|
from classiq.qmod.builtins.functions.standard_gates import H
|
3
|
-
from classiq.qmod.builtins.functions.utility_functions import apply_to_all
|
4
4
|
from classiq.qmod.builtins.operations import control, invert, power, repeat
|
5
5
|
from classiq.qmod.cparam import CInt
|
6
6
|
from classiq.qmod.qfunc import qfunc
|
@@ -1,13 +1,15 @@
|
|
1
1
|
from typing import Literal
|
2
2
|
|
3
|
-
from classiq.
|
3
|
+
from classiq.open_library.functions.utility_functions import (
|
4
|
+
hadamard_transform,
|
5
|
+
modular_increment,
|
6
|
+
)
|
7
|
+
from classiq.qmod.builtins.functions import allocate
|
4
8
|
from classiq.qmod.builtins.functions.standard_gates import CX, IDENTITY, RY, H, X
|
5
|
-
from classiq.qmod.builtins.functions.utility_functions import hadamard_transform
|
6
9
|
from classiq.qmod.builtins.operations import control, if_, repeat
|
7
10
|
from classiq.qmod.cparam import CBool, CInt
|
8
11
|
from classiq.qmod.qfunc import qfunc
|
9
|
-
from classiq.qmod.
|
10
|
-
from classiq.qmod.qmod_variable import Input, Output, QArray, QBit, QNum
|
12
|
+
from classiq.qmod.qmod_variable import Output, QArray, QBit, QNum
|
11
13
|
from classiq.qmod.symbolic import (
|
12
14
|
asin,
|
13
15
|
atan,
|
@@ -21,31 +23,6 @@ from classiq.qmod.symbolic import (
|
|
21
23
|
)
|
22
24
|
|
23
25
|
|
24
|
-
@qfunc(external=True)
|
25
|
-
def allocate(
|
26
|
-
num_qubits: CInt, out: Output[QArray[QBit, Literal["num_qubits"]]]
|
27
|
-
) -> None:
|
28
|
-
"""
|
29
|
-
[Qmod core-library function]
|
30
|
-
|
31
|
-
Allocates the specified number of qubits to a given quantum variable and initializes
|
32
|
-
them in the zero state:
|
33
|
-
|
34
|
-
$$
|
35
|
-
\\left|\\text{out}\\right\\rangle = \\left|0\\right\\rangle^{\\otimes \\text{num_qubits}}
|
36
|
-
$$
|
37
|
-
|
38
|
-
Args:
|
39
|
-
num_qubits: The number of qubits to allocate. Must be a positive integer.
|
40
|
-
out: The quantum variable that will receive the allocated qubits. Must be uninitialized before allocation.
|
41
|
-
|
42
|
-
Notes:
|
43
|
-
1. If the output variable has been declared with a specific number of qubits, the number of qubits allocated must match the declared number.
|
44
|
-
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
45
|
-
"""
|
46
|
-
pass
|
47
|
-
|
48
|
-
|
49
26
|
@qfunc
|
50
27
|
def allocate_num(
|
51
28
|
num_qubits: CInt,
|
@@ -68,126 +45,6 @@ def allocate_num(
|
|
68
45
|
allocate(num_qubits, out)
|
69
46
|
|
70
47
|
|
71
|
-
@qfunc(external=True)
|
72
|
-
def free(in_: Input[QArray[QBit]]) -> None:
|
73
|
-
"""
|
74
|
-
[Qmod core-library function]
|
75
|
-
|
76
|
-
Releases the qubits allocated to a quantum variable, allowing them to be reused.
|
77
|
-
|
78
|
-
Args:
|
79
|
-
in_: The quantum variable that will be freed. Must be initialized before.
|
80
|
-
|
81
|
-
Note:
|
82
|
-
This operation does not uncompute the qubits. It is the responsibility of the user to ensure that the qubits are at the zero state before freeing them.
|
83
|
-
"""
|
84
|
-
pass
|
85
|
-
|
86
|
-
|
87
|
-
@qfunc(external=True)
|
88
|
-
def prepare_state(
|
89
|
-
probabilities: CArray[CReal],
|
90
|
-
bound: CReal,
|
91
|
-
out: Output[QArray[QBit, Literal["log(get_field(probabilities, 'len'), 2)"]]],
|
92
|
-
) -> None:
|
93
|
-
"""
|
94
|
-
[Qmod core-library function]
|
95
|
-
|
96
|
-
Initializes a quantum variable in a state corresponding to a given probability distribution:
|
97
|
-
|
98
|
-
$$
|
99
|
-
\\left|\\text{out}\\right\\rangle = \\sum_{i=0}^{\\text{len(probabilities)}-1} \\sqrt{\\text{probabilities}[i]} \\left|i\\right\\rangle
|
100
|
-
$$
|
101
|
-
|
102
|
-
with $i = 0, 1, 2, ..., \\text{len(amplitudes)}-1$ corresponding to computational basis states.
|
103
|
-
|
104
|
-
Args:
|
105
|
-
probabilities: The probability distribution to initialize the quantum variable. Must be a valid probability distribution, i.e., a list of non-negative real numbers that sum to 1. Must have a valid length (a power of 2).
|
106
|
-
bound: An error bound, expressed as the $L^{2}$ norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number.
|
107
|
-
out: The quantum variable that will receive the initialized state. Must be uninitialized.
|
108
|
-
|
109
|
-
Notes:
|
110
|
-
1. If the output variable has been declared with a specific number of qubits, the number of qubits formed by the distribution must match the declared number.
|
111
|
-
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
112
|
-
"""
|
113
|
-
pass
|
114
|
-
|
115
|
-
|
116
|
-
@qfunc(external=True)
|
117
|
-
def prepare_amplitudes(
|
118
|
-
amplitudes: CArray[CReal],
|
119
|
-
bound: CReal,
|
120
|
-
out: Output[QArray[QBit, Literal["log(get_field(amplitudes, 'len'), 2)"]]],
|
121
|
-
) -> None:
|
122
|
-
"""
|
123
|
-
[Qmod core-library function]
|
124
|
-
|
125
|
-
Initializes a quantum variable in a state corresponding to the given amplitudes:
|
126
|
-
|
127
|
-
$$
|
128
|
-
\\left|\\text{out}\\right\\rangle = \\sum_{i=0}^{\\text{len(amplitudes)}-1} \\text{amplitudes}[i] \\left|i\\right\\rangle
|
129
|
-
$$
|
130
|
-
|
131
|
-
with $i = 0, 1, 2, ..., \\text{len(amplitudes)}-1$ corresponding to computational basis states.
|
132
|
-
|
133
|
-
Args:
|
134
|
-
amplitudes: The amplitudes to initialize the quantum variable. Must be a valid real quantum state vector, i.e., the sum of squares should be 1. Must have a valid length (a power of 2).
|
135
|
-
bound: An error bound, expressed as the $L^{2}$ norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number.
|
136
|
-
out: The quantum variable that will receive the initialized state. Must be uninitialized.
|
137
|
-
|
138
|
-
Notes:
|
139
|
-
1. If the output variable has been declared with a specific number of qubits, the number of qubits formed by the distribution must match the declared number.
|
140
|
-
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
141
|
-
"""
|
142
|
-
pass
|
143
|
-
|
144
|
-
|
145
|
-
@qfunc(external=True)
|
146
|
-
def inplace_prepare_state(
|
147
|
-
probabilities: CArray[CReal],
|
148
|
-
bound: CReal,
|
149
|
-
target: QArray[QBit, Literal["log(get_field(probabilities, 'len'), 2)"]],
|
150
|
-
) -> None:
|
151
|
-
"""
|
152
|
-
[Qmod core-library function]
|
153
|
-
|
154
|
-
Transforms a given quantum variable in the state |0> to the state per the specified probability distribution
|
155
|
-
(similar to `prepare_state` but preformed on an initialized variable).
|
156
|
-
|
157
|
-
Args:
|
158
|
-
probabilities: The probability distribution corresponding to the quantum variable state. Must be a valid probability distribution, i.e., a list of non-negative real numbers that sum to 1. Must have a valid length (a power of 2).
|
159
|
-
bound: An error bound, expressed as the $L^{2}$ norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number.
|
160
|
-
target: The quantum variable to act upon.
|
161
|
-
|
162
|
-
This is useful as part of quantum building blocks like the Grover diffuser operator, $\\left|\\psi\\right\\rangle\\left\\langle\\psi\\right| \\left( 2\\left|0\\right\\rangle\\left\\langle0\\right| - \\mathcal{I} \\right)$, where the output state of the oracle is reflected about this state.
|
163
|
-
|
164
|
-
"""
|
165
|
-
pass
|
166
|
-
|
167
|
-
|
168
|
-
@qfunc(external=True)
|
169
|
-
def inplace_prepare_amplitudes(
|
170
|
-
amplitudes: CArray[CReal],
|
171
|
-
bound: CReal,
|
172
|
-
target: QArray[QBit, Literal["log(get_field(amplitudes, 'len'), 2)"]],
|
173
|
-
) -> None:
|
174
|
-
"""
|
175
|
-
[Qmod core-library function]
|
176
|
-
|
177
|
-
Transforms a given quantum variable in the state |0> to the state per the specified amplitudes
|
178
|
-
(similar to `prepare_amplitudes` but preformed on an initialized variable).
|
179
|
-
|
180
|
-
Args:
|
181
|
-
amplitudes: The amplitudes to initialize the quantum variable. Must be a valid real quantum state vector, i.e., the sum of squares should be 1. Must have a valid length (a power of 2).
|
182
|
-
bound: An error bound, expressed as the $L^{2}$ norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number.
|
183
|
-
target: The quantum variable to act upon.
|
184
|
-
|
185
|
-
This is useful as part of quantum building blocks like the Grover diffuser operator, $\\left|\\psi\\right\\rangle\\left\\langle\\psi\\right| \\left( 2\\left|0\\right\\rangle\\left\\langle0\\right| - \\mathcal{I} \\right)$, where the output state of the oracle is reflected about this state.
|
186
|
-
|
187
|
-
"""
|
188
|
-
pass
|
189
|
-
|
190
|
-
|
191
48
|
def prepare_uniform_trimmed_state_apply_rotation(
|
192
49
|
size_lsb: CInt, lsbs_val: CInt, rotation_var: QBit
|
193
50
|
) -> None:
|
@@ -1,5 +1,5 @@
|
|
1
|
+
from classiq.qmod.builtins.functions import allocate
|
1
2
|
from classiq.qmod.builtins.functions.standard_gates import SWAP, H
|
2
|
-
from classiq.qmod.builtins.functions.state_preparation import allocate
|
3
3
|
from classiq.qmod.builtins.operations import control, repeat
|
4
4
|
from classiq.qmod.qfunc import qfunc
|
5
5
|
from classiq.qmod.qmod_variable import Output, QArray, QBit
|
@@ -0,0 +1,81 @@
|
|
1
|
+
from typing import Annotated
|
2
|
+
|
3
|
+
from classiq.open_library.functions.qft_functions import qft
|
4
|
+
from classiq.qmod.builtins.functions.standard_gates import PHASE, H
|
5
|
+
from classiq.qmod.builtins.operations import bind, repeat, within_apply
|
6
|
+
from classiq.qmod.cparam import CInt
|
7
|
+
from classiq.qmod.qfunc import qfunc
|
8
|
+
from classiq.qmod.qmod_variable import QArray, QBit, QCallable, QNum
|
9
|
+
from classiq.qmod.quantum_callable import QCallableList
|
10
|
+
from classiq.qmod.symbolic import pi
|
11
|
+
|
12
|
+
|
13
|
+
@qfunc
|
14
|
+
def apply_to_all(
|
15
|
+
gate_operand: QCallable[Annotated[QBit, "target"]], target: QArray[QBit]
|
16
|
+
) -> None:
|
17
|
+
"""
|
18
|
+
[Qmod Classiq-library function]
|
19
|
+
|
20
|
+
Applies the single-qubit operand `gate_operand` to each qubit in the qubit
|
21
|
+
array `target`.
|
22
|
+
|
23
|
+
Args:
|
24
|
+
gate_operand: The single-qubit gate to apply to each qubit in the array.
|
25
|
+
target: The qubit array to apply the gate to.
|
26
|
+
"""
|
27
|
+
repeat(target.len, lambda index: gate_operand(target[index]))
|
28
|
+
|
29
|
+
|
30
|
+
@qfunc
|
31
|
+
def hadamard_transform(target: QArray[QBit]) -> None:
|
32
|
+
"""
|
33
|
+
[Qmod Classiq-library function]
|
34
|
+
|
35
|
+
Applies Hadamard transform to the target qubits.
|
36
|
+
|
37
|
+
Corresponds to the braket notation:
|
38
|
+
|
39
|
+
$$
|
40
|
+
H^{\\otimes n} |x\rangle = \frac{1}{\\sqrt{2^n}} \\sum_{y=0}^{2^n - 1} (-1)^{x \\cdot y} |y\rangle
|
41
|
+
$$
|
42
|
+
|
43
|
+
Args:
|
44
|
+
target: qubits to apply to Hadamard transform to.
|
45
|
+
|
46
|
+
"""
|
47
|
+
apply_to_all(H, target)
|
48
|
+
|
49
|
+
|
50
|
+
@qfunc
|
51
|
+
def switch(selector: CInt, cases: QCallableList) -> None:
|
52
|
+
cases[selector]()
|
53
|
+
|
54
|
+
|
55
|
+
@qfunc
|
56
|
+
def modular_increment(a: CInt, x: QNum) -> None:
|
57
|
+
"""
|
58
|
+
[Qmod Classiq-library function]
|
59
|
+
|
60
|
+
Adds $a$ to $x$ modulo the range of $x$, assumed that $x$ is a non-negative integer and $a$ is an integer.
|
61
|
+
Mathematically it is described as:
|
62
|
+
|
63
|
+
$$
|
64
|
+
x = (x+a)\\ \\mod \\ 2^{x.size}-1
|
65
|
+
$$
|
66
|
+
|
67
|
+
Args:
|
68
|
+
a: A classical integer to be added to x.
|
69
|
+
x: A quantum number that is assumed to be non-negative integer.
|
70
|
+
|
71
|
+
"""
|
72
|
+
array_cast: QArray = QArray("array_cast")
|
73
|
+
within_apply(
|
74
|
+
lambda: ( # type:ignore[arg-type]
|
75
|
+
bind(x, array_cast), # type:ignore[func-returns-value]
|
76
|
+
qft(array_cast),
|
77
|
+
),
|
78
|
+
lambda: repeat(
|
79
|
+
x.size, lambda i: PHASE(a * 2 * pi * 2**i / (2**x.size), array_cast[i])
|
80
|
+
),
|
81
|
+
)
|
@@ -1,5 +1,5 @@
|
|
1
|
+
from classiq.qmod.builtins.functions import allocate
|
1
2
|
from classiq.qmod.builtins.functions.standard_gates import RX, RY, RZ
|
2
|
-
from classiq.qmod.builtins.functions.state_preparation import allocate
|
3
3
|
from classiq.qmod.builtins.operations import repeat
|
4
4
|
from classiq.qmod.cparam import CReal
|
5
5
|
from classiq.qmod.qfunc import qfunc
|
@@ -1,29 +1,12 @@
|
|
1
|
-
from .
|
1
|
+
from .allocation import *
|
2
2
|
from .arithmetic import *
|
3
3
|
from .benchmarking import *
|
4
4
|
from .chemistry import *
|
5
|
-
from .discrete_sine_cosine_transform import *
|
6
|
-
from .discrete_sine_cosine_transform import _qct_d_operator, _qct_pi_operator
|
7
5
|
from .exponentiation import *
|
8
6
|
from .finance import *
|
9
|
-
from .grover import *
|
10
|
-
from .hea import *
|
11
|
-
from .linear_pauli_rotation import *
|
12
|
-
from .linear_pauli_rotation import _single_pauli
|
13
|
-
from .modular_exponentiation import *
|
14
|
-
from .modular_exponentiation import _check_msb, _ctrl_x
|
15
7
|
from .operators import *
|
16
|
-
from .qaoa_penalty import *
|
17
|
-
from .qft_functions import *
|
18
|
-
from .qpe import *
|
19
8
|
from .qsvm import *
|
20
|
-
from .qsvt import *
|
21
9
|
from .standard_gates import *
|
22
|
-
from .state_preparation import *
|
23
|
-
from .state_preparation import _prepare_uniform_trimmed_state_step
|
24
|
-
from .swap_test import *
|
25
|
-
from .utility_functions import *
|
26
|
-
from .variational import *
|
27
10
|
|
28
11
|
CORE_LIB_DECLS = [
|
29
12
|
func.func_decl
|
@@ -87,70 +70,8 @@ CORE_LIB_DECLS = [
|
|
87
70
|
)
|
88
71
|
]
|
89
72
|
|
90
|
-
OPEN_LIBRARY_FUNCTIONS = [
|
91
|
-
qpe_flexible,
|
92
|
-
qpe,
|
93
|
-
_single_pauli,
|
94
|
-
linear_pauli_rotations,
|
95
|
-
amplitude_estimation,
|
96
|
-
phase_oracle,
|
97
|
-
reflect_about_zero,
|
98
|
-
grover_diffuser,
|
99
|
-
grover_operator,
|
100
|
-
grover_search,
|
101
|
-
hadamard_transform,
|
102
|
-
apply_to_all,
|
103
|
-
qft_no_swap,
|
104
|
-
qft_space_add_const,
|
105
|
-
cc_modular_add,
|
106
|
-
c_modular_multiply,
|
107
|
-
multiswap,
|
108
|
-
inplace_c_modular_multiply,
|
109
|
-
modular_exp,
|
110
|
-
qsvt_step,
|
111
|
-
qsvt,
|
112
|
-
projector_controlled_double_phase,
|
113
|
-
projector_controlled_phase,
|
114
|
-
qsvt_inversion,
|
115
|
-
qsvt_lcu,
|
116
|
-
qsvt_lcu_step,
|
117
|
-
allocate_num,
|
118
|
-
qaoa_mixer_layer,
|
119
|
-
qaoa_cost_layer,
|
120
|
-
qaoa_layer,
|
121
|
-
qaoa_init,
|
122
|
-
qaoa_penalty,
|
123
|
-
full_hea,
|
124
|
-
swap_test,
|
125
|
-
prepare_uniform_trimmed_state,
|
126
|
-
prepare_uniform_interval_state,
|
127
|
-
prepare_ghz_state,
|
128
|
-
prepare_exponential_state,
|
129
|
-
prepare_bell_state,
|
130
|
-
inplace_prepare_int,
|
131
|
-
prepare_int,
|
132
|
-
switch,
|
133
|
-
qct_qst_type1,
|
134
|
-
qct_qst_type2,
|
135
|
-
qct_type2,
|
136
|
-
qst_type2,
|
137
|
-
modular_increment,
|
138
|
-
qft,
|
139
|
-
_ctrl_x,
|
140
|
-
_prepare_uniform_trimmed_state_step,
|
141
|
-
_qct_d_operator,
|
142
|
-
_qct_pi_operator,
|
143
|
-
_check_msb,
|
144
|
-
encode_in_angle,
|
145
|
-
encode_on_bloch,
|
146
|
-
]
|
147
|
-
|
148
73
|
STD_QMOD_OPERATORS = [func.func_decl for func in (apply, permute)]
|
149
74
|
|
150
|
-
BUILTIN_FUNCTION_DECLARATIONS = {
|
151
|
-
func_decl.name: func_decl for func_decl in STD_QMOD_OPERATORS + CORE_LIB_DECLS
|
152
|
-
}
|
153
|
-
|
154
75
|
__all__ = [ # noqa: RUF022
|
155
76
|
"CCX",
|
156
77
|
"CH",
|
@@ -181,83 +102,36 @@ __all__ = [ # noqa: RUF022
|
|
181
102
|
"X",
|
182
103
|
"Y",
|
183
104
|
"Z",
|
184
|
-
"_single_pauli",
|
185
105
|
"add",
|
186
106
|
"allocate",
|
187
|
-
"allocate_num",
|
188
|
-
"amplitude_estimation",
|
189
107
|
"apply",
|
190
|
-
"apply_to_all",
|
191
108
|
"bloch_sphere_feature_map",
|
192
|
-
"c_modular_multiply",
|
193
|
-
"cc_modular_add",
|
194
|
-
"encode_in_angle",
|
195
|
-
"encode_on_bloch",
|
196
109
|
"exponentiation_with_depth_constraint",
|
197
110
|
"fock_hamiltonian_hartree_fock",
|
198
111
|
"fock_hamiltonian_hva",
|
199
112
|
"fock_hamiltonian_ucc",
|
200
113
|
"free",
|
201
|
-
"full_hea",
|
202
114
|
"gaussian_finance",
|
203
|
-
"grover_diffuser",
|
204
|
-
"grover_operator",
|
205
|
-
"grover_search",
|
206
|
-
"hadamard_transform",
|
207
|
-
"inplace_c_modular_multiply",
|
208
115
|
"inplace_prepare_amplitudes",
|
209
|
-
"inplace_prepare_int",
|
210
116
|
"inplace_prepare_state",
|
211
117
|
"integer_xor",
|
212
|
-
"linear_pauli_rotations",
|
213
118
|
"log_normal_finance",
|
214
119
|
"modular_add",
|
215
120
|
"modular_add_constant",
|
216
|
-
"modular_exp",
|
217
|
-
"modular_increment",
|
218
121
|
"molecule_hartree_fock",
|
219
122
|
"molecule_hva",
|
220
123
|
"molecule_ucc",
|
221
|
-
"multiswap",
|
222
124
|
"pauli_feature_map",
|
223
125
|
"permute",
|
224
|
-
"phase_oracle",
|
225
126
|
"prepare_amplitudes",
|
226
|
-
"prepare_bell_state",
|
227
|
-
"prepare_exponential_state",
|
228
|
-
"prepare_ghz_state",
|
229
|
-
"prepare_int",
|
230
127
|
"prepare_state",
|
231
|
-
"prepare_uniform_interval_state",
|
232
|
-
"prepare_uniform_trimmed_state",
|
233
|
-
"projector_controlled_double_phase",
|
234
|
-
"projector_controlled_phase",
|
235
|
-
"qaoa_cost_layer",
|
236
|
-
"qaoa_init",
|
237
|
-
"qaoa_layer",
|
238
|
-
"qaoa_mixer_layer",
|
239
|
-
"qaoa_penalty",
|
240
|
-
"qct_qst_type1",
|
241
|
-
"qct_qst_type2",
|
242
|
-
"qct_type2",
|
243
128
|
"qdrift",
|
244
|
-
"qft",
|
245
|
-
"qft_no_swap",
|
246
|
-
"qft_space_add_const",
|
247
|
-
"qpe",
|
248
|
-
"qpe_flexible",
|
249
|
-
"qst_type2",
|
250
|
-
"qsvt",
|
251
|
-
"qsvt_inversion",
|
252
|
-
"qsvt_lcu",
|
253
|
-
"qsvt_lcu_step",
|
254
|
-
"qsvt_step",
|
255
129
|
"randomized_benchmarking",
|
256
130
|
"real_xor_constant",
|
257
|
-
"reflect_about_zero",
|
258
131
|
"single_pauli_exponent",
|
259
132
|
"suzuki_trotter",
|
260
|
-
"swap_test",
|
261
|
-
"switch",
|
262
133
|
"unitary",
|
263
134
|
]
|
135
|
+
BUILTIN_FUNCTION_DECLARATIONS = {
|
136
|
+
func_decl.name: func_decl for func_decl in STD_QMOD_OPERATORS + CORE_LIB_DECLS
|
137
|
+
}
|