pennylane-qrack 0.21.2__py3-none-win_amd64.whl → 0.22.0__py3-none-win_amd64.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.

Potentially problematic release.


This version of pennylane-qrack might be problematic. Click here for more details.

@@ -0,0 +1,99 @@
1
+ schema = 3
2
+
3
+ # The set of all gate types supported at the runtime execution interface of the
4
+ # device, i.e., what is supported by the `execute` method. The gate definitions
5
+ # should have the following format:
6
+ #
7
+ # GATE = { properties = [ PROPS ], conditions = [ CONDS ] }
8
+ #
9
+ # where PROPS and CONS are zero or more comma separated quoted strings.
10
+ #
11
+ # PROPS: additional support provided for each gate.
12
+ # - "controllable": if a controlled version of this gate is supported.
13
+ # - "invertible": if the adjoint of this operation is supported.
14
+ # - "differentiable": if device gradient is supported for this gate.
15
+ # CONDS: constraints on the support for each gate.
16
+ # - "analytic" or "finiteshots": if this operation is only supported in
17
+ # either analytic execution or with shots, respectively.
18
+ #
19
+ [operators.gates]
20
+
21
+ PauliX = { properties = [ "controllable", "invertible" ] }
22
+ PauliY = { properties = [ "controllable", "invertible" ] }
23
+ PauliZ = { properties = [ "controllable", "invertible" ] }
24
+ Hadamard = { properties = [ "invertible" ] }
25
+ S = { properties = [ "invertible" ] }
26
+ CNOT = { properties = [ "invertible" ] }
27
+ SWAP = { properties = [ "invertible" ] }
28
+ ISWAP = { properties = [ "invertible" ] }
29
+ PSWAP = { properties = [ "invertible" ] }
30
+ CY = { properties = [ "invertible" ] }
31
+ CZ = { properties = [ "invertible" ] }
32
+ Identity = { properties = [ "controllable", "invertible" ] }
33
+
34
+ # Observables supported by the device for measurements. The observables defined
35
+ # in this section should have the following format:
36
+ #
37
+ # OBSERVABLE = { conditions = [ CONDS ] }
38
+ #
39
+ # where CONDS is zero or more comma separated quoted strings, same as above.
40
+ #
41
+ # CONDS: constraints on the support for each observable.
42
+ # - "analytic" or "finiteshots": if this observable is only supported in
43
+ # either analytic execution or with shots, respectively.
44
+ # - "terms-commute": if a composite operator is only supported under the
45
+ # condition that its terms commute.
46
+ #
47
+ [operators.observables]
48
+
49
+ PauliX = {}
50
+ PauliY = {}
51
+ PauliZ = {}
52
+ Identity = {}
53
+ Prod = {}
54
+ # Hadamard = {}
55
+ # Hermitian = {}
56
+ # Projector = {}
57
+ # SparseHamiltonian = {}
58
+ # Hamiltonian = {}
59
+ # Sum = {}
60
+ # SProd = {}
61
+ # Exp = {}
62
+
63
+ # Types of measurement processes supported on the device. The measurements in
64
+ # this section should have the following format:
65
+ #
66
+ # MEASUREMENT_PROCESS = { conditions = [ CONDS ] }
67
+ #
68
+ # where CONDS is zero or more comma separated quoted strings, same as above.
69
+ #
70
+ # CONDS: constraints on the support for each measurement process.
71
+ # - "analytic" or "finiteshots": if this measurement is only supported
72
+ # in either analytic execution or with shots, respectively.
73
+ #
74
+ [measurement_processes]
75
+
76
+ ExpectationMP = { conditions = [ "analytic" ] }
77
+ VarianceMP = { conditions = [ "analytic" ] }
78
+ ProbabilityMP = { conditions = [ "analytic" ] }
79
+ StateMP = { conditions = [ "analytic" ] }
80
+ SampleMP = { conditions = [ "finiteshots" ] }
81
+ CountsMP = { conditions = [ "finiteshots" ] }
82
+
83
+ # Additional support that the device may provide that informs the compilation
84
+ # process. All accepted fields and their default values are listed below.
85
+ [compilation]
86
+
87
+ # Whether the device is compatible with qjit.
88
+ qjit_compatible = false
89
+
90
+ # Whether the device requires run time generation of the quantum circuit.
91
+ runtime_code_generation = false
92
+
93
+ # Whether the device supports allocating and releasing qubits during execution.
94
+ dynamic_qubit_management = false
95
+
96
+ # The methods of handling mid-circuit measurements that the device supports,
97
+ # e.g., "one-shot", "tree-traversal", "device", etc. An empty list indicates
98
+ # that the device does not support mid-circuit measurements.
99
+ supported_mcm_methods = [ "device", "one-shot" ]
@@ -16,4 +16,4 @@
16
16
  Version number (major.minor.patch[-label])
17
17
  """
18
18
 
19
- __version__ = "0.21.2"
19
+ __version__ = "0.22.0"
@@ -51,7 +51,7 @@ tolerance = 1e-10
51
51
  class QrackAceDevice(QubitDevice):
52
52
  """Qrack Ace device"""
53
53
 
54
- name = "Qrack device"
54
+ name = "Qrack Ace device"
55
55
  short_name = "qrack.ace"
56
56
  pennylane_requires = ">=0.11.0"
57
57
  version = __version__
@@ -0,0 +1,296 @@
1
+ # Copyright 2020 Xanadu Quantum Technologies Inc.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """
15
+ Base device class for PennyLane-Qrack.
16
+ """
17
+ from functools import reduce
18
+ import cmath, math
19
+ import os
20
+ import pathlib
21
+ import sys
22
+ import itertools as it
23
+
24
+ import numpy as np
25
+
26
+ # PennyLane v0.42 introduced the `exceptions` module and will raise
27
+ # deprecation warnings if they are imported from the top-level module.
28
+
29
+ # This ensures backwards compatibility with older versions of PennyLane.
30
+ try:
31
+ from pennylane.exceptions import DeviceError, QuantumFunctionError
32
+ except (ModuleNotFoundError, ImportError) as import_error:
33
+ from pennylane import DeviceError, QuantumFunctionError
34
+
35
+ from pennylane.devices import QubitDevice
36
+ from pennylane.ops import (
37
+ BasisState,
38
+ Adjoint,
39
+ )
40
+ from pennylane.wires import Wires
41
+
42
+ from pyqrack import QrackStabilizer, Pauli
43
+
44
+ from ._version import __version__
45
+ from sys import platform as _platform
46
+
47
+ # tolerance for numerical errors
48
+ tolerance = 1e-10
49
+
50
+
51
+ class QrackStabilizerDevice(QubitDevice):
52
+ """Qrack Stabilizer device"""
53
+
54
+ name = "Qrack stabilizer device"
55
+ short_name = "qrack.stabilizer"
56
+ pennylane_requires = ">=0.11.0"
57
+ version = __version__
58
+ author = "Daniel Strano, adapted from Steven Oud and Xanadu"
59
+
60
+ _capabilities = {
61
+ "model": "qubit",
62
+ "tensor_observables": True,
63
+ "inverse_operations": True,
64
+ "returns_state": True,
65
+ }
66
+
67
+ _observable_map = {
68
+ "PauliX": Pauli.PauliX,
69
+ "PauliY": Pauli.PauliY,
70
+ "PauliZ": Pauli.PauliZ,
71
+ "Identity": Pauli.PauliI,
72
+ "Hadamard": None,
73
+ "Hermitian": None,
74
+ "Prod": None,
75
+ # "Sum": None,
76
+ # "SProd": None,
77
+ # "Exp": None,
78
+ # "Projector": None,
79
+ # "Hamiltonian": None,
80
+ # "SparseHamiltonian": None
81
+ }
82
+
83
+ observables = _observable_map.keys()
84
+ operations = {
85
+ "Identity",
86
+ "C(Identity)",
87
+ "SWAP",
88
+ "ISWAP",
89
+ "PSWAP",
90
+ "CNOT",
91
+ "CY",
92
+ "CZ",
93
+ "S",
94
+ "PauliX",
95
+ "C(PauliX)",
96
+ "PauliY",
97
+ "C(PauliY)",
98
+ "PauliZ",
99
+ "C(PauliZ)",
100
+ "Hadamard",
101
+ "SX",
102
+ }
103
+
104
+ config_filepath = pathlib.Path(
105
+ os.path.dirname(sys.modules[__name__].__file__) + "/QrackStabilizerDeviceConfig.toml"
106
+ )
107
+
108
+ def __init__(self, wires=0, shots=None, **kwargs):
109
+ super().__init__(wires=wires, shots=shots)
110
+ self.shots = shots
111
+ self._state = QrackStabilizer(self.num_wires)
112
+ self.device_kwargs = {}
113
+
114
+ def _reverse_state(self):
115
+ end = self.num_wires - 1
116
+ mid = self.num_wires >> 1
117
+ for i in range(mid):
118
+ self._state.swap(i, end - i)
119
+
120
+ def apply(self, operations, **kwargs):
121
+ for op in operations:
122
+ if isinstance(op, BasisState):
123
+ self._apply_basis_state(op)
124
+ else:
125
+ self._apply_gate(op)
126
+
127
+ def _apply_basis_state(self, op):
128
+ """Initialize a basis state"""
129
+ wires = self.map_wires(Wires(op.wires))
130
+ par = op.parameters[0]
131
+ wire_count = len(wires)
132
+ n_basis_state = len(par)
133
+
134
+ if not set(par).issubset({0, 1}):
135
+ raise ValueError("BasisState parameter must consist of 0 or 1 integers.")
136
+ if n_basis_state != wire_count:
137
+ raise ValueError("BasisState parameter and wires must be of equal length.")
138
+
139
+ for i in range(wire_count):
140
+ index = wires.labels[i]
141
+ if par[i] != self._state.m(index):
142
+ self._state.x(index)
143
+
144
+ def _apply_gate(self, op):
145
+ """Apply native qrack gate"""
146
+
147
+ opname = op.name
148
+ if isinstance(op, Adjoint):
149
+ op = op.base
150
+ opname = op.name + ".inv"
151
+
152
+ par = op.parameters
153
+
154
+ # translate op wire labels to consecutive wire labels used by the device
155
+ device_wires = self.map_wires(
156
+ (op.control_wires + op.wires) if op.control_wires else op.wires
157
+ )
158
+
159
+ if opname in [
160
+ "".join(p)
161
+ for p in it.product(
162
+ [
163
+ "CNOT",
164
+ "C(PauliX)",
165
+ ],
166
+ ["", ".inv"],
167
+ )
168
+ ]:
169
+ self._state.mcx(device_wires.labels[:-1], device_wires.labels[-1])
170
+ elif opname in ["C(PauliY)", "C(PauliY).inv"]:
171
+ self._state.mcy(device_wires.labels[:-1], device_wires.labels[-1])
172
+ elif opname in ["C(PauliZ)", "C(PauliZ).inv"]:
173
+ self._state.mcz(device_wires.labels[:-1], device_wires.labels[-1])
174
+ elif opname in ["SWAP", "SWAP.inv"]:
175
+ self._state.swap(device_wires.labels[0], device_wires.labels[1])
176
+ elif opname == "ISWAP":
177
+ self._state.iswap(device_wires.labels[0], device_wires.labels[1])
178
+ elif opname == "ISWAP.inv":
179
+ self._state.adjiswap(device_wires.labels[0], device_wires.labels[1])
180
+ elif opname in ["CY", "CY.inv", "C(CY)", "C(CY).inv"]:
181
+ self._state.mcy(device_wires.labels[:-1], device_wires.labels[-1])
182
+ elif opname in ["CZ", "CZ.inv", "C(CZ)", "C(CZ).inv"]:
183
+ self._state.mcz(device_wires.labels[:-1], device_wires.labels[-1])
184
+ elif opname == "S":
185
+ for label in device_wires.labels:
186
+ self._state.s(label)
187
+ elif opname == "S.inv":
188
+ for label in device_wires.labels:
189
+ self._state.adjs(label)
190
+ elif opname in ["PauliX", "PauliX.inv"]:
191
+ for label in device_wires.labels:
192
+ self._state.x(label)
193
+ elif opname in ["PauliY", "PauliY.inv"]:
194
+ for label in device_wires.labels:
195
+ self._state.y(label)
196
+ elif opname in ["PauliZ", "PauliZ.inv"]:
197
+ for label in device_wires.labels:
198
+ self._state.z(label)
199
+ elif opname in ["Hadamard", "Hadamard.inv"]:
200
+ for label in device_wires.labels:
201
+ self._state.h(label)
202
+ elif opname == "SX":
203
+ half_pi = math.pi / 2
204
+ for label in device_wires.labels:
205
+ self._state.u(label, half_pi, -half_pi, half.pi)
206
+ elif opname == "SX.inv":
207
+ half_pi = math.pi / 2
208
+ for label in device_wires.labels:
209
+ self._state.u(label, -half_pi, -half.pi, half_pi)
210
+ elif opname not in [
211
+ "Identity",
212
+ "Identity.inv",
213
+ "C(Identity)",
214
+ "C(Identity).inv",
215
+ ]:
216
+ raise DeviceError(f"Operation {opname} is not supported on a {self.short_name} device.")
217
+
218
+ def analytic_probability(self, wires=None):
219
+ """Return the (marginal) analytic probability of each computational basis state."""
220
+ if self._state is None:
221
+ return None
222
+
223
+ all_probs = self._abs(self.state) ** 2
224
+ prob = self.marginal_prob(all_probs, wires)
225
+
226
+ if (not "QRACK_FPPOW" in os.environ) or (6 > int(os.environ.get("QRACK_FPPOW"))):
227
+ tot_prob = 0
228
+ for p in prob:
229
+ tot_prob = tot_prob + p
230
+
231
+ if tot_prob != 1.0:
232
+ for i in range(len(prob)):
233
+ prob[i] = prob[i] / tot_prob
234
+
235
+ return prob
236
+
237
+ def expval(self, observable, **kwargs):
238
+ if self.shots is None:
239
+ if isinstance(observable.name, list):
240
+ b = [self._observable_map[obs] for obs in observable.name]
241
+ elif observable.name == "Prod":
242
+ b = [self._observable_map[obs.name] for obs in observable.operands]
243
+ else:
244
+ b = [self._observable_map[observable.name]]
245
+
246
+ if None not in b:
247
+ q = self.map_wires(observable.wires)
248
+ return self._state.pauli_expectation(q, b)
249
+
250
+ # exact expectation value
251
+ if callable(observable.eigvals):
252
+ eigvals = self._asarray(observable.eigvals(), dtype=self.R_DTYPE)
253
+ else: # older version of pennylane
254
+ eigvals = self._asarray(observable.eigvals, dtype=self.R_DTYPE)
255
+ prob = self.probability(wires=observable.wires)
256
+ return self._dot(eigvals, prob)
257
+
258
+ # estimate the ev
259
+ return np.mean(self.sample(observable))
260
+
261
+ def _generate_sample(self):
262
+ rev_sample = self._state.m_all()
263
+ sample = 0
264
+ for i in range(self.num_wires):
265
+ if (rev_sample & (1 << i)) > 0:
266
+ sample |= 1 << (self.num_wires - (i + 1))
267
+ return sample
268
+
269
+ def generate_samples(self):
270
+ if self.shots is None:
271
+ raise QuantumFunctionError(
272
+ "The number of shots has to be explicitly set on the device "
273
+ "when using sample-based measurements."
274
+ )
275
+
276
+ return self._samples
277
+
278
+ if self.shots == 1:
279
+ self._samples = QubitDevice.states_to_binary(
280
+ np.array([self._generate_sample()]), self.num_wires
281
+ )
282
+
283
+ return self._samples
284
+
285
+ # QubitDevice.states_to_binary() doesn't work for >64qb. (Fix by Elara, the custom OpenAI GPT)
286
+ samples = self._state.measure_shots(list(range(self.num_wires - 1, -1, -1)), self.shots)
287
+ self._samples = np.array(
288
+ [list(format(b, f"0{self.num_wires}b")) for b in samples], dtype=np.int8
289
+ )
290
+
291
+ return self._samples
292
+
293
+ def reset(self):
294
+ for i in range(self.num_wires):
295
+ if self._state.m(i):
296
+ self._state.x(i)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pennylane-qrack
3
- Version: 0.21.2
3
+ Version: 0.22.0
4
4
  Summary: PennyLane plugin for Qrack.
5
5
  Home-page: http://github.com/vm6502q
6
6
  Maintainer: vm6502q
@@ -54,7 +54,8 @@ Features
54
54
 
55
55
  * Provides access to a PyQrack simulator backend via the ``qrack.simulator`` device
56
56
  * Provides access to a (C++) Qrack simulator backend for Catalyst (also) via the ``qrack.simulator`` device
57
- * Provides access to a PyQrack simulator backend optimized for approximate NISQ-scale TFIM via the ``qrack.ace`` device
57
+ * Provides access to a PyQrack Clifford-only simulator backend via the ``qrack.stabilizer`` device
58
+ * Provides access to a PyQrack simulator backend optimized for large-scale approximate simulation via the ``qrack.ace`` device
58
59
 
59
60
  .. installation-start-inclusion-marker-do-not-remove
60
61
 
@@ -0,0 +1,15 @@
1
+ pennylane_qrack/QrackAceDeviceConfig.toml,sha256=zrGB9gVmB105WX4s7MS-MceoXC5sNTRysxNa_StBpl0,4625
2
+ pennylane_qrack/QrackDeviceConfig.toml,sha256=M3rIJH9GlMJv6lapfSXses5qauSvezs8OqnHYLq6in0,5576
3
+ pennylane_qrack/QrackStabilizerDeviceConfig.toml,sha256=njxwgqpEEYHvuYINdaBuwXM8i44Nl5TsdIC5zZw-Rag,4064
4
+ pennylane_qrack/__init__.py,sha256=5iuZ5OqhRPLxj5cs9jGaUTDv55iPXRVbcDHM6FNk-5c,689
5
+ pennylane_qrack/_version.py,sha256=p3ja1VG6k0t1YXYNOlXn-tUoFzsiyVRKpYunVrS9UoQ,708
6
+ pennylane_qrack/qrack_ace_device.py,sha256=HvZ3Hbb4pTo7rLfHwyRNTO7TPxJVdBdHf47COpuURok,17540
7
+ pennylane_qrack/qrack_device.cpp,sha256=E-TO_11A0GlCSJisFtUlT0EERjJD_bsTvlBvNNBeTn8,38065
8
+ pennylane_qrack/qrack_device.py,sha256=Aart7lENzYKPNcZiN36UrZgQTc8lo18-DO3LTyu-rEs,29096
9
+ pennylane_qrack/qrack_stabilizer_device.py,sha256=ehRghmj3kgOB1uCBhz-EdDLtNot4eQXM2l-NQe4ieIA,10254
10
+ pennylane_qrack-0.22.0.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
11
+ pennylane_qrack-0.22.0.dist-info/METADATA,sha256=DWa8Ux-QJIZg3NY2n6dEs7Dn_CHGkCcn3zeH7cxm0AY,6092
12
+ pennylane_qrack-0.22.0.dist-info/WHEEL,sha256=JMWfR_Dj7ISokcwe0cBhCfK6JKnIi-ZX11L6d_ntt6o,98
13
+ pennylane_qrack-0.22.0.dist-info/entry_points.txt,sha256=5eoa4LFV7DuSLFbs6tzFvuVIHr6zOovxqlDsn2cinP4,220
14
+ pennylane_qrack-0.22.0.dist-info/top_level.txt,sha256=5NFMNHqCHtVLwNkLg66xz846uUJAlnOJ5VGa6ulW1ow,16
15
+ pennylane_qrack-0.22.0.dist-info/RECORD,,
@@ -1,3 +1,4 @@
1
1
  [pennylane.plugins]
2
2
  qrack.ace = pennylane_qrack.qrack_ace_device:QrackAceDevice
3
3
  qrack.simulator = pennylane_qrack.qrack_device:QrackDevice
4
+ qrack.stabilizer = pennylane_qrack.qrack_stabilizer_device:QrackStabilizerDevice
@@ -1,13 +0,0 @@
1
- pennylane_qrack/QrackAceDeviceConfig.toml,sha256=zrGB9gVmB105WX4s7MS-MceoXC5sNTRysxNa_StBpl0,4625
2
- pennylane_qrack/QrackDeviceConfig.toml,sha256=M3rIJH9GlMJv6lapfSXses5qauSvezs8OqnHYLq6in0,5576
3
- pennylane_qrack/__init__.py,sha256=5iuZ5OqhRPLxj5cs9jGaUTDv55iPXRVbcDHM6FNk-5c,689
4
- pennylane_qrack/_version.py,sha256=TPvaCI11I9z9k0fRa7O7YGV1vOUZDwhXCfKJDgLGVjg,708
5
- pennylane_qrack/qrack_ace_device.py,sha256=lfqAhutsl__zKgGta8fbBtnIycbzODuT6MG_LJfsOOk,17536
6
- pennylane_qrack/qrack_device.cpp,sha256=E-TO_11A0GlCSJisFtUlT0EERjJD_bsTvlBvNNBeTn8,38065
7
- pennylane_qrack/qrack_device.py,sha256=Aart7lENzYKPNcZiN36UrZgQTc8lo18-DO3LTyu-rEs,29096
8
- pennylane_qrack-0.21.2.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
9
- pennylane_qrack-0.21.2.dist-info/METADATA,sha256=kohtHymF9t3x33jh-bk9AajU0V3YZ31DBxtASzwjZZg,5985
10
- pennylane_qrack-0.21.2.dist-info/WHEEL,sha256=JMWfR_Dj7ISokcwe0cBhCfK6JKnIi-ZX11L6d_ntt6o,98
11
- pennylane_qrack-0.21.2.dist-info/entry_points.txt,sha256=OrkJ6JVk-yndlQjqc-8dm8PxE-jNoNQRFXFeUBxVuCg,139
12
- pennylane_qrack-0.21.2.dist-info/top_level.txt,sha256=5NFMNHqCHtVLwNkLg66xz846uUJAlnOJ5VGa6ulW1ow,16
13
- pennylane_qrack-0.21.2.dist-info/RECORD,,