tequila-basic 1.9.9__py3-none-any.whl → 1.9.10__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.
- tequila/__init__.py +29 -14
- tequila/apps/__init__.py +14 -5
- tequila/apps/_unary_state_prep_impl.py +145 -112
- tequila/apps/adapt/__init__.py +9 -1
- tequila/apps/adapt/adapt.py +154 -113
- tequila/apps/krylov/__init__.py +1 -1
- tequila/apps/krylov/krylov.py +23 -21
- tequila/apps/robustness/helpers.py +10 -6
- tequila/apps/robustness/interval.py +238 -156
- tequila/apps/unary_state_prep.py +29 -23
- tequila/autograd_imports.py +8 -5
- tequila/circuit/__init__.py +2 -1
- tequila/circuit/_gates_impl.py +135 -67
- tequila/circuit/circuit.py +163 -79
- tequila/circuit/compiler.py +114 -105
- tequila/circuit/gates.py +288 -120
- tequila/circuit/gradient.py +35 -23
- tequila/circuit/noise.py +83 -74
- tequila/circuit/postselection.py +120 -0
- tequila/circuit/pyzx.py +10 -6
- tequila/circuit/qasm.py +201 -83
- tequila/circuit/qpic.py +63 -61
- tequila/grouping/binary_rep.py +148 -146
- tequila/grouping/binary_utils.py +84 -75
- tequila/grouping/compile_groups.py +334 -230
- tequila/grouping/ev_utils.py +77 -41
- tequila/grouping/fermionic_functions.py +383 -308
- tequila/grouping/fermionic_methods.py +170 -123
- tequila/grouping/overlapping_methods.py +69 -52
- tequila/hamiltonian/paulis.py +12 -13
- tequila/hamiltonian/paulistring.py +1 -1
- tequila/hamiltonian/qubit_hamiltonian.py +45 -35
- tequila/ml/__init__.py +1 -0
- tequila/ml/interface_torch.py +19 -16
- tequila/ml/ml_api.py +11 -10
- tequila/ml/utils_ml.py +12 -11
- tequila/objective/__init__.py +8 -3
- tequila/objective/braket.py +55 -47
- tequila/objective/objective.py +87 -55
- tequila/objective/qtensor.py +36 -27
- tequila/optimizers/__init__.py +31 -23
- tequila/optimizers/_containers.py +11 -7
- tequila/optimizers/optimizer_base.py +111 -83
- tequila/optimizers/optimizer_gd.py +258 -231
- tequila/optimizers/optimizer_gpyopt.py +56 -42
- tequila/optimizers/optimizer_scipy.py +157 -112
- tequila/quantumchemistry/__init__.py +66 -38
- tequila/quantumchemistry/chemistry_tools.py +393 -209
- tequila/quantumchemistry/encodings.py +121 -13
- tequila/quantumchemistry/madness_interface.py +170 -96
- tequila/quantumchemistry/orbital_optimizer.py +86 -41
- tequila/quantumchemistry/psi4_interface.py +166 -97
- tequila/quantumchemistry/pyscf_interface.py +70 -23
- tequila/quantumchemistry/qc_base.py +866 -414
- tequila/simulators/__init__.py +0 -3
- tequila/simulators/simulator_api.py +247 -105
- tequila/simulators/simulator_aqt.py +102 -0
- tequila/simulators/simulator_base.py +147 -53
- tequila/simulators/simulator_cirq.py +58 -42
- tequila/simulators/simulator_cudaq.py +600 -0
- tequila/simulators/simulator_ddsim.py +390 -0
- tequila/simulators/simulator_mqp.py +30 -0
- tequila/simulators/simulator_pyquil.py +190 -171
- tequila/simulators/simulator_qibo.py +95 -87
- tequila/simulators/simulator_qiskit.py +119 -107
- tequila/simulators/simulator_qlm.py +52 -26
- tequila/simulators/simulator_qulacs.py +74 -52
- tequila/simulators/simulator_spex.py +95 -60
- tequila/simulators/simulator_symbolic.py +6 -5
- tequila/simulators/test_spex_simulator.py +8 -11
- tequila/tools/convenience.py +4 -4
- tequila/tools/qng.py +72 -64
- tequila/tools/random_generators.py +38 -34
- tequila/utils/bitstrings.py +7 -7
- tequila/utils/exceptions.py +19 -5
- tequila/utils/joined_transformation.py +8 -10
- tequila/utils/keymap.py +0 -5
- tequila/utils/misc.py +6 -4
- tequila/version.py +1 -1
- tequila/wavefunction/qubit_wavefunction.py +47 -28
- {tequila_basic-1.9.9.dist-info → tequila_basic-1.9.10.dist-info}/METADATA +13 -16
- tequila_basic-1.9.10.dist-info/RECORD +93 -0
- {tequila_basic-1.9.9.dist-info → tequila_basic-1.9.10.dist-info}/WHEEL +1 -1
- tequila_basic-1.9.9.dist-info/RECORD +0 -88
- {tequila_basic-1.9.9.dist-info → tequila_basic-1.9.10.dist-info}/licenses/LICENSE +0 -0
- {tequila_basic-1.9.9.dist-info → tequila_basic-1.9.10.dist-info}/top_level.txt +0 -0
@@ -7,13 +7,14 @@ from tequila.utils import to_float
|
|
7
7
|
|
8
8
|
import importlib
|
9
9
|
import numpy as np
|
10
|
-
import typing
|
10
|
+
import typing
|
11
|
+
import numbers
|
11
12
|
|
12
13
|
import cirq
|
13
14
|
import cirq_google
|
14
15
|
|
15
|
-
map_1 = lambda x: {
|
16
|
-
map_2 = lambda x: {
|
16
|
+
map_1 = lambda x: {"exponent": x}
|
17
|
+
map_2 = lambda x: {"exponent": x / np.pi, "global_shift": -0.5}
|
17
18
|
|
18
19
|
|
19
20
|
def qubit_satisfier(op, level):
|
@@ -85,7 +86,7 @@ class BackendCircuitCirq(BackendCircuit):
|
|
85
86
|
"controlled_phase": True,
|
86
87
|
"toffoli": False,
|
87
88
|
"phase_to_z": False,
|
88
|
-
"cc_max": False
|
89
|
+
"cc_max": False,
|
89
90
|
}
|
90
91
|
|
91
92
|
numbering: BitNumbering = BitNumbering.MSB
|
@@ -113,23 +114,30 @@ class BackendCircuitCirq(BackendCircuit):
|
|
113
114
|
"""
|
114
115
|
|
115
116
|
self.op_lookup = {
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
117
|
+
"I": (cirq.ops.IdentityGate, None),
|
118
|
+
"X": (cirq.ops.common_gates.XPowGate, map_1),
|
119
|
+
"Y": (cirq.ops.common_gates.YPowGate, map_1),
|
120
|
+
"Z": (cirq.ops.common_gates.ZPowGate, map_1),
|
121
|
+
"H": (cirq.ops.common_gates.HPowGate, map_1),
|
122
|
+
"Rx": (cirq.ops.common_gates.XPowGate, map_2),
|
123
|
+
"Ry": (cirq.ops.common_gates.YPowGate, map_2),
|
124
|
+
"Rz": (cirq.ops.common_gates.ZPowGate, map_2),
|
125
|
+
"SWAP": (cirq.ops.SwapPowGate, None),
|
125
126
|
}
|
126
127
|
|
127
128
|
self.tq_to_sympy = {}
|
128
129
|
self.counter = 0
|
129
130
|
if device is not None:
|
130
|
-
self.compiler_arguments[
|
131
|
-
super().__init__(
|
132
|
-
|
131
|
+
self.compiler_arguments["cc_max"] = True
|
132
|
+
super().__init__(
|
133
|
+
abstract_circuit=abstract_circuit,
|
134
|
+
variables=variables,
|
135
|
+
noise=noise,
|
136
|
+
qubit_map=qubit_map,
|
137
|
+
device=device,
|
138
|
+
*args,
|
139
|
+
**kwargs,
|
140
|
+
)
|
133
141
|
if len(self.tq_to_sympy.keys()) is None:
|
134
142
|
self.sympy_to_tq = None
|
135
143
|
self.resolver = None
|
@@ -139,15 +147,15 @@ class BackendCircuitCirq(BackendCircuit):
|
|
139
147
|
if self.device is not None:
|
140
148
|
self.circuit = self.build_device_circuit()
|
141
149
|
if self.noise is not None:
|
142
|
-
if self.noise ==
|
143
|
-
raise TequilaException(
|
150
|
+
if self.noise == "device":
|
151
|
+
raise TequilaException("cannot get device noise for cirq yet, sorry!")
|
144
152
|
self.noise_lookup = {
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
153
|
+
"bit flip": [lambda x: cirq.bit_flip(x)],
|
154
|
+
"phase flip": [lambda x: cirq.phase_flip(x)],
|
155
|
+
"phase damp": [cirq.phase_damp],
|
156
|
+
"amplitude damp": [cirq.amplitude_damp],
|
157
|
+
"phase-amplitude damp": [cirq.amplitude_damp, cirq.phase_damp],
|
158
|
+
"depolarizing": [lambda x: cirq.depolarize(p=(3 / 4) * x)],
|
151
159
|
}
|
152
160
|
self.circuit = self.build_noisy_circuit(self.noise)
|
153
161
|
|
@@ -171,8 +179,9 @@ class BackendCircuitCirq(BackendCircuit):
|
|
171
179
|
|
172
180
|
"""
|
173
181
|
simulator = cirq.Simulator()
|
174
|
-
backend_result = simulator.simulate(
|
175
|
-
|
182
|
+
backend_result = simulator.simulate(
|
183
|
+
program=self.circuit, param_resolver=self.resolver, initial_state=initial_state
|
184
|
+
)
|
176
185
|
return QubitWaveFunction.from_array(array=backend_result.final_state_vector, numbering=self.numbering)
|
177
186
|
|
178
187
|
def convert_measurements(self, backend_result: cirq.Result) -> QubitWaveFunction:
|
@@ -189,7 +198,7 @@ class BackendCircuitCirq(BackendCircuit):
|
|
189
198
|
the result of sampling, as a tequila QubitWaveFunction.
|
190
199
|
|
191
200
|
"""
|
192
|
-
assert
|
201
|
+
assert len(backend_result.measurements) == 1
|
193
202
|
for key, value in backend_result.measurements.items():
|
194
203
|
counter = QubitWaveFunction(self.n_qubits, self.numbering)
|
195
204
|
for sample in value:
|
@@ -218,7 +227,9 @@ class BackendCircuitCirq(BackendCircuit):
|
|
218
227
|
QubitWaveFunction:
|
219
228
|
the result of sampled measurement, as a tequila wavefunction.
|
220
229
|
"""
|
221
|
-
return self.convert_measurements(
|
230
|
+
return self.convert_measurements(
|
231
|
+
cirq.sample(program=circuit, param_resolver=self.resolver, repetitions=samples)
|
232
|
+
)
|
222
233
|
|
223
234
|
def no_translation(self, abstract_circuit):
|
224
235
|
return isinstance(abstract_circuit, cirq.Circuit)
|
@@ -257,15 +268,15 @@ class BackendCircuitCirq(BackendCircuit):
|
|
257
268
|
"""
|
258
269
|
op, mapping = self.op_lookup[gate.name]
|
259
270
|
parameter = gate.parameter
|
260
|
-
if hasattr(gate,
|
271
|
+
if hasattr(gate, "power"):
|
261
272
|
parameter = gate.power
|
262
273
|
if isinstance(parameter, float):
|
263
274
|
par = parameter
|
264
275
|
else:
|
265
276
|
try:
|
266
277
|
par = self.tq_to_sympy[parameter]
|
267
|
-
except:
|
268
|
-
par = sympy.Symbol(
|
278
|
+
except Exception:
|
279
|
+
par = sympy.Symbol("{}_{}".format(self._name_variable_objective(parameter), str(self.counter)))
|
269
280
|
self.tq_to_sympy[parameter] = par
|
270
281
|
self.counter += 1
|
271
282
|
cirq_gate = op(**mapping(par)).on(*[self.qubit(t) for t in gate.target])
|
@@ -314,7 +325,7 @@ class BackendCircuitCirq(BackendCircuit):
|
|
314
325
|
"""
|
315
326
|
target_qubits = sorted(target_qubits)
|
316
327
|
cirq_gate = cirq.MeasurementGate(len(target_qubits)).on(*[self.qubit(t) for t in target_qubits])
|
317
|
-
return circuit + cirq_gate
|
328
|
+
return circuit + cirq_gate # avoid inplace operations for measurements
|
318
329
|
|
319
330
|
def make_qubit_map(self, qubits) -> typing.Dict[numbers.Integral, cirq.LineQubit]:
|
320
331
|
"""
|
@@ -358,23 +369,27 @@ class BackendCircuitCirq(BackendCircuit):
|
|
358
369
|
line = None
|
359
370
|
circuit = None
|
360
371
|
if isinstance(device, cirq.Device):
|
361
|
-
HAS_GOOGLE = importlib.util.find_spec(
|
362
|
-
assert HAS_GOOGLE, TequilaCirqException(
|
363
|
-
|
372
|
+
HAS_GOOGLE = importlib.util.find_spec("cirq_google")
|
373
|
+
assert HAS_GOOGLE, TequilaCirqException(" cirq_google package is not installed.")
|
374
|
+
|
364
375
|
if device in [cirq_google.Sycamore, cirq_google.Sycamore23]:
|
365
376
|
try:
|
366
377
|
circuit = cirq.optimize_for_target_gateset(circuit=c, gateset=cirq_google.SycamoreTargetGateset())
|
367
378
|
except ValueError as E:
|
368
379
|
original_message = str(E)
|
369
|
-
raise TequilaCirqException(
|
380
|
+
raise TequilaCirqException(
|
381
|
+
"original message:\n{}\n\ncould not optimize for device={}".format(original_message, device)
|
382
|
+
)
|
370
383
|
else:
|
371
384
|
### under construction (potentially on other branches)
|
372
|
-
raise TequilaException(
|
385
|
+
raise TequilaException("Only Sycamore and Sycamore23 devices currently functional. Sorry!")
|
373
386
|
|
374
387
|
else:
|
375
388
|
raise TequilaException(
|
376
|
-
|
377
|
-
|
389
|
+
"build_device_circuit demands a cirq.Device object; received {}, of type {}".format(
|
390
|
+
str(device), type(device)
|
391
|
+
)
|
392
|
+
)
|
378
393
|
return circuit
|
379
394
|
|
380
395
|
def build_noisy_circuit(self, noise):
|
@@ -444,7 +459,7 @@ class BackendCircuitCirq(BackendCircuit):
|
|
444
459
|
if isinstance(device, cirq.Device):
|
445
460
|
return device
|
446
461
|
else:
|
447
|
-
raise TequilaException(
|
462
|
+
raise TequilaException("Unable to retrieve requested device, {}, in cirq".format(str(device)))
|
448
463
|
|
449
464
|
def check_device(self, device):
|
450
465
|
"""
|
@@ -464,14 +479,15 @@ class BackendCircuitCirq(BackendCircuit):
|
|
464
479
|
return
|
465
480
|
else:
|
466
481
|
assert isinstance(device, str)
|
467
|
-
if device.lower() in [
|
482
|
+
if device.lower() in ["sycamore", "sycamore23"]:
|
468
483
|
pass
|
469
484
|
else:
|
470
|
-
raise TequilaException(
|
485
|
+
raise TequilaException("requested device {} could not be found!".format(device))
|
471
486
|
|
472
487
|
|
473
488
|
class BackendExpectationValueCirq(BackendExpectationValue):
|
474
489
|
"""
|
475
490
|
See BackendExpectationValue for details.
|
476
491
|
"""
|
492
|
+
|
477
493
|
BackendCircuitType = BackendCircuitCirq
|