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
@@ -8,84 +8,91 @@ from pyquil.noise import combine_kraus_maps
|
|
8
8
|
from tequila.utils import to_float
|
9
9
|
|
10
10
|
name_dict = {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
11
|
+
"I": "I",
|
12
|
+
"ry": "parametrized",
|
13
|
+
"rx": "parametrized",
|
14
|
+
"rz": "parametrized",
|
15
|
+
"Rz": "parametrized",
|
16
|
+
"Ry": "parametrized",
|
17
|
+
"Rx": "parametrized",
|
18
|
+
"RZ": "parametrized",
|
19
|
+
"RY": "parametrized",
|
20
|
+
"RX": "parametrized",
|
21
|
+
"r": "parametrized",
|
22
|
+
"X": "X",
|
23
|
+
"x": "X",
|
24
|
+
"Y": "Y",
|
25
|
+
"y": "Y",
|
26
|
+
"Z": "Z",
|
27
|
+
"z": "Z",
|
28
|
+
"Cz": "control",
|
29
|
+
"CZ": "control",
|
30
|
+
"cz": "control",
|
31
|
+
"SWAP": "control",
|
32
|
+
"CX": "control",
|
33
|
+
"Cx": "control",
|
34
|
+
"cx": "control",
|
35
|
+
"CNOT": "control",
|
36
|
+
"ccx": "multicontrol",
|
37
|
+
"CCx": "multicontrol",
|
38
|
+
"CSWAP": "multicontrol",
|
39
|
+
"H": "H",
|
40
|
+
"h": "H",
|
41
|
+
"Phase": "parametrized",
|
42
|
+
"PHASE": "parametrized",
|
43
43
|
}
|
44
44
|
|
45
45
|
gate_qubit_lookup = {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
46
|
+
"X": 1,
|
47
|
+
"Y": 1,
|
48
|
+
"Z": 1,
|
49
|
+
"H": 1,
|
50
|
+
"RX": 1,
|
51
|
+
"RY": 1,
|
52
|
+
"RZ": 1,
|
53
|
+
"CX": 2,
|
54
|
+
"CY": 2,
|
55
|
+
"CZ": 2,
|
56
|
+
"CH": 2,
|
57
|
+
"CRX": 2,
|
58
|
+
"CRY": 2,
|
59
|
+
"CRZ": 2,
|
60
|
+
"CNOT": 2,
|
61
|
+
"CCNOT": 3,
|
62
62
|
}
|
63
63
|
|
64
64
|
name_unitary_dict = {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
65
|
+
"I": np.eye(2),
|
66
|
+
"X": np.array([[0.0, 1.0], [1.0, 0.0]]),
|
67
|
+
"Y": np.array([[0.0, -1.0j], [1.0j, 0.0]]),
|
68
|
+
"Z": np.array([[1.0, 0.0], [0.0, -1.0]]),
|
69
|
+
"H": np.array([[1 / np.sqrt(2), 1 / np.sqrt(2)], [1 / np.sqrt(2), -1 / np.sqrt(2)]]),
|
70
|
+
"CNOT": np.array(
|
71
|
+
[
|
72
|
+
[1.0, 0.0, 0.0, 0.0],
|
73
|
+
[
|
74
|
+
0.0,
|
75
|
+
1.0,
|
76
|
+
0.0,
|
77
|
+
0.0,
|
78
|
+
],
|
79
|
+
[0.0, 0.0, 0.0, 1.0],
|
80
|
+
[0.0, 0.0, 1.0, 0.0],
|
81
|
+
]
|
82
|
+
),
|
83
|
+
"SWAP": np.array([[1.0, 0.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0]]),
|
84
|
+
"CCNOT": np.array(
|
85
|
+
[
|
86
|
+
[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
|
87
|
+
[0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
|
88
|
+
[0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
|
89
|
+
[0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
|
90
|
+
[0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
|
91
|
+
[0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
|
92
|
+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
|
93
|
+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
|
94
|
+
]
|
95
|
+
),
|
89
96
|
}
|
90
97
|
|
91
98
|
|
@@ -98,8 +105,7 @@ def amp_damp_map(p):
|
|
98
105
|
:return: A list [k1, k2] of the Kraus operators that parametrize the map.
|
99
106
|
:rtype: list
|
100
107
|
"""
|
101
|
-
damping_op = np.sqrt(p) * np.array([[0, 1],
|
102
|
-
[0, 0]])
|
108
|
+
damping_op = np.sqrt(p) * np.array([[0, 1], [0, 0]])
|
103
109
|
|
104
110
|
residual_kraus = np.diag([1, np.sqrt(1 - p)])
|
105
111
|
return [residual_kraus, damping_op]
|
@@ -199,7 +205,7 @@ def depolarizing_map(p):
|
|
199
205
|
mat1 = np.array([[np.sqrt(1 - 3 * p / 4), 0], [0, np.sqrt(1 - 3 * p / 4)]])
|
200
206
|
mat2 = np.array([[np.sqrt(p / 4), 0], [0, -np.sqrt(p / 4)]])
|
201
207
|
mat3 = np.array([[0, np.sqrt(p / 4)], [np.sqrt(p / 4), 0]])
|
202
|
-
mat4 = np.array([[0
|
208
|
+
mat4 = np.array([[0.0, -1.0j * np.sqrt(p / 4)], [1.0j * np.sqrt(p / 4), 0.0]])
|
203
209
|
return [mat1, mat2, mat3, mat4]
|
204
210
|
|
205
211
|
|
@@ -225,7 +231,7 @@ def kraus_tensor(klist, n):
|
|
225
231
|
elif n >= 3:
|
226
232
|
return [np.kron(k1, k2) for k1 in kraus_tensor(klist, n - 1) for k2 in klist]
|
227
233
|
else:
|
228
|
-
raise TequilaPyquilException(
|
234
|
+
raise TequilaPyquilException("wtf, you gave me n={}".format(str(n)))
|
229
235
|
|
230
236
|
|
231
237
|
def append_kraus_to_gate(kraus_ops, g, level):
|
@@ -268,8 +274,8 @@ def add_controls(matrix, count):
|
|
268
274
|
controls = count - gc
|
269
275
|
if int(controls) == 0:
|
270
276
|
return matrix
|
271
|
-
new = np.eye(2
|
272
|
-
new[-matrix.shape[0]:, -matrix.shape[0]:] = matrix
|
277
|
+
new = np.eye(2**count)
|
278
|
+
new[-matrix.shape[0] :, -matrix.shape[0] :] = matrix
|
273
279
|
return new
|
274
280
|
|
275
281
|
|
@@ -324,6 +330,7 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
324
330
|
takes in a noise model and a circuit and applies noise to it.
|
325
331
|
|
326
332
|
"""
|
333
|
+
|
327
334
|
compiler_arguments = {
|
328
335
|
"trotterized": True,
|
329
336
|
"swap": False,
|
@@ -339,13 +346,12 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
339
346
|
"controlled_phase": False,
|
340
347
|
"toffoli": False,
|
341
348
|
"phase_to_z": False,
|
342
|
-
"cc_max": False
|
349
|
+
"cc_max": False,
|
343
350
|
}
|
344
351
|
|
345
352
|
numbering = BitNumbering.LSB
|
346
353
|
|
347
|
-
def __init__(self, abstract_circuit: QCircuit, variables, qubit_map=None, noise=None, device=None, *args,
|
348
|
-
**kwargs):
|
354
|
+
def __init__(self, abstract_circuit: QCircuit, variables, qubit_map=None, noise=None, device=None, *args, **kwargs):
|
349
355
|
"""
|
350
356
|
Parameters
|
351
357
|
----------
|
@@ -367,39 +373,47 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
367
373
|
"""
|
368
374
|
|
369
375
|
self.op_lookup = {
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
376
|
+
"I": (pyquil.gates.I),
|
377
|
+
"X": (pyquil.gates.X, pyquil.gates.CNOT, pyquil.gates.CCNOT),
|
378
|
+
"Y": (pyquil.gates.Y,),
|
379
|
+
"Z": (pyquil.gates.Z, pyquil.gates.CZ),
|
380
|
+
"H": (pyquil.gates.H,),
|
381
|
+
"Rx": pyquil.gates.RX,
|
382
|
+
"Ry": pyquil.gates.RY,
|
383
|
+
"Rz": pyquil.gates.RZ,
|
384
|
+
"Phase": pyquil.gates.PHASE,
|
385
|
+
"SWAP": (pyquil.gates.SWAP, pyquil.gates.CSWAP),
|
380
386
|
}
|
381
387
|
self.match_par_to_dummy = {}
|
382
388
|
self.counter = 0
|
383
389
|
if device is not None:
|
384
|
-
self.compiler_arguments[
|
385
|
-
super().__init__(
|
386
|
-
|
390
|
+
self.compiler_arguments["cc_max"] = True
|
391
|
+
super().__init__(
|
392
|
+
abstract_circuit=abstract_circuit,
|
393
|
+
variables=variables,
|
394
|
+
noise=noise,
|
395
|
+
device=device,
|
396
|
+
qubit_map=qubit_map,
|
397
|
+
*args,
|
398
|
+
**kwargs,
|
399
|
+
)
|
387
400
|
if self.noise is not None:
|
388
401
|
self.noise_lookup = {
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
402
|
+
"amplitude damp": amp_damp_map,
|
403
|
+
"phase damp": phase_damp_map,
|
404
|
+
"bit flip": bit_flip_map,
|
405
|
+
"phase flip": phase_flip_map,
|
406
|
+
"phase-amplitude damp": phase_amp_damp_map,
|
407
|
+
"depolarizing": depolarizing_map,
|
395
408
|
}
|
396
409
|
|
397
410
|
if isinstance(self.noise, str):
|
398
|
-
if self.noise ==
|
411
|
+
if self.noise == "device":
|
399
412
|
pass
|
400
413
|
else:
|
401
414
|
raise TequilaException(
|
402
|
-
|
415
|
+
"noise was a string: {}, which is not 'device'. This is not allowed!".format(self.noise)
|
416
|
+
)
|
403
417
|
|
404
418
|
else:
|
405
419
|
self.circuit = self.build_noisy_circuit(self.circuit, self.noise)
|
@@ -408,8 +422,9 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
408
422
|
self.match_dummy_to_value = None
|
409
423
|
self.resolver = None
|
410
424
|
else:
|
411
|
-
self.match_dummy_to_value = {
|
412
|
-
|
425
|
+
self.match_dummy_to_value = {
|
426
|
+
"theta_{}".format(str(i)): k for i, k in enumerate(self.match_par_to_dummy.keys())
|
427
|
+
}
|
413
428
|
self.resolver = {k: [to_float(v(variables))] for k, v in self.match_dummy_to_value.items()}
|
414
429
|
|
415
430
|
def do_simulate(self, variables, initial_state, *args, **kwargs):
|
@@ -464,12 +479,12 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
464
479
|
p = circuit
|
465
480
|
|
466
481
|
if self.device is None:
|
467
|
-
qc = get_qc(
|
482
|
+
qc = get_qc("{}q-qvm".format(str(n_qubits)))
|
468
483
|
p.wrap_in_numshots_loop(samples)
|
469
484
|
else:
|
470
485
|
qc = self.device
|
471
486
|
p = qc.compile(p)
|
472
|
-
p.attributes[
|
487
|
+
p.attributes["num_shots"] = samples
|
473
488
|
stacked = qc.run(p, memory_map=self.resolver)
|
474
489
|
return self.convert_measurements(stacked)
|
475
490
|
|
@@ -491,7 +506,7 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
491
506
|
def string_to_array(s):
|
492
507
|
listing = []
|
493
508
|
for letter in s:
|
494
|
-
if letter not in [
|
509
|
+
if letter not in [",", " ", "[", "]", "."]:
|
495
510
|
listing.append(int(letter))
|
496
511
|
return listing
|
497
512
|
|
@@ -500,7 +515,7 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
500
515
|
for b in backend_result:
|
501
516
|
try:
|
502
517
|
bit_dict[str(b)] += 1
|
503
|
-
except:
|
518
|
+
except Exception:
|
504
519
|
bit_dict[str(b)] = 1
|
505
520
|
|
506
521
|
for k, v in bit_dict.items():
|
@@ -528,30 +543,30 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
528
543
|
|
529
544
|
def add_parametrized_gate(self, gate, circuit, *args, **kwargs):
|
530
545
|
"""
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
546
|
+
Add a parametrized gate to the circuit. Used in inherited method create_circuit.
|
547
|
+
|
548
|
+
Additionally, builds and updates mappings so that pyquil can resolve the parametrization of the gate at runtime.
|
549
|
+
Parameters
|
550
|
+
----------
|
551
|
+
gate: QGateImpl:
|
552
|
+
the gate to translate to pyquil.
|
553
|
+
circuit:
|
554
|
+
the pyquil circuit, to which a new gate is to be added
|
555
|
+
args
|
556
|
+
kwargs
|
557
|
+
|
558
|
+
Returns
|
559
|
+
-------
|
560
|
+
None
|
561
|
+
"""
|
547
562
|
op = self.op_lookup[gate.name]
|
548
563
|
if isinstance(gate.parameter, float):
|
549
564
|
par = gate.parameter
|
550
565
|
else:
|
551
566
|
try:
|
552
567
|
par = self.match_par_to_dummy[gate.parameter]
|
553
|
-
except:
|
554
|
-
par = circuit.declare(
|
568
|
+
except Exception:
|
569
|
+
par = circuit.declare("theta_{}".format(str(self.counter)), "REAL")
|
555
570
|
self.match_par_to_dummy[gate.parameter] = par
|
556
571
|
self.counter += 1
|
557
572
|
pyquil_gate = op(angle=par, qubit=self.qubit(gate.target[0]))
|
@@ -562,26 +577,26 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
562
577
|
|
563
578
|
def add_measurement(self, circuit, target_qubits, *args, **kwargs):
|
564
579
|
"""
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
580
|
+
Add a measurement to the circuit. Used in inherited method create_circuit.
|
581
|
+
|
582
|
+
----------
|
583
|
+
gate: MeasurementGateImpl:
|
584
|
+
the measurement, to be translated to pyquil
|
585
|
+
circuit:
|
586
|
+
the pyquil circuit, to which measurement is to be added
|
587
|
+
args
|
588
|
+
kwargs
|
589
|
+
|
590
|
+
Returns
|
591
|
+
-------
|
592
|
+
None
|
593
|
+
"""
|
579
594
|
bits = len(target_qubits)
|
580
595
|
measurements = self.initialize_circuit()
|
581
|
-
ro = measurements.declare(
|
596
|
+
ro = measurements.declare("ro", "BIT", bits)
|
582
597
|
for i, t in enumerate(sorted(target_qubits)):
|
583
598
|
measurements += pyquil.gates.MEASURE(self.qubit(t), ro[i])
|
584
|
-
return circuit + measurements
|
599
|
+
return circuit + measurements # avoid inplace operations
|
585
600
|
|
586
601
|
def add_basic_gate(self, gate, circuit, *args, **kwargs):
|
587
602
|
"""
|
@@ -606,7 +621,7 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
606
621
|
pyquil_gate = g(*[self.qubit(q) for q in gate.control + gate.target])
|
607
622
|
else:
|
608
623
|
pyquil_gate = g(*[self.qubit(t) for t in gate.target])
|
609
|
-
except:
|
624
|
+
except Exception:
|
610
625
|
g = op[0]
|
611
626
|
for c in gate.control:
|
612
627
|
pyquil_gate = g(*[self.qubit(t) for t in gate.target]).controlled(self.qubit(c))
|
@@ -633,30 +648,31 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
633
648
|
collected = {}
|
634
649
|
for noise in noise_model.noises:
|
635
650
|
try:
|
636
|
-
collected[str(noise.level)] = combine_kraus_maps(
|
637
|
-
|
638
|
-
|
651
|
+
collected[str(noise.level)] = combine_kraus_maps(
|
652
|
+
self.noise_lookup[noise.name](*noise.probs), collected[str(noise.level)]
|
653
|
+
)
|
654
|
+
except Exception:
|
639
655
|
collected[str(noise.level)] = self.noise_lookup[noise.name](*noise.probs)
|
640
656
|
done = []
|
641
657
|
for gate in prog:
|
642
658
|
new.inst(gate)
|
643
|
-
if hasattr(gate,
|
659
|
+
if hasattr(gate, "qubits"):
|
644
660
|
level = str(len(gate.qubits))
|
645
661
|
if level in collected.keys():
|
646
|
-
if name_dict[gate.name] ==
|
662
|
+
if name_dict[gate.name] == "parametrized":
|
647
663
|
new.inst([pyquil.gates.I(q) for q in gate.qubits])
|
648
|
-
if [
|
649
|
-
new.define_noisy_gate(
|
650
|
-
|
651
|
-
|
652
|
-
done.append([
|
664
|
+
if ["parametrized", gate.qubits] not in done:
|
665
|
+
new.define_noisy_gate(
|
666
|
+
"I", gate.qubits, append_kraus_to_gate(collected[level], np.eye(2), int(level))
|
667
|
+
)
|
668
|
+
done.append(["parametrized", 1, gate.qubits])
|
653
669
|
|
654
670
|
else:
|
655
671
|
if [gate.name, len(gate.qubits), gate.qubits] not in done:
|
656
672
|
k = unitary_maker(gate)
|
657
|
-
new.define_noisy_gate(
|
658
|
-
|
659
|
-
|
673
|
+
new.define_noisy_gate(
|
674
|
+
gate.name, gate.qubits, append_kraus_to_gate(collected[level], k, int(level))
|
675
|
+
)
|
660
676
|
done.append([gate.name, len(gate.qubits), gate.qubits])
|
661
677
|
else:
|
662
678
|
pass
|
@@ -698,9 +714,9 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
698
714
|
return
|
699
715
|
if isinstance(device, str):
|
700
716
|
d = device
|
701
|
-
if
|
717
|
+
if "-qvm" in d.lower():
|
702
718
|
d = d[:-4]
|
703
|
-
if
|
719
|
+
if "-noisy" in d.lower():
|
704
720
|
d = d[:-6]
|
705
721
|
if d in pyquil.list_quantum_computers():
|
706
722
|
return
|
@@ -708,25 +724,26 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
708
724
|
try:
|
709
725
|
get_qc(d)
|
710
726
|
return
|
711
|
-
except:
|
727
|
+
except Exception:
|
712
728
|
try:
|
713
729
|
get_qc(d, as_qvm=True)
|
714
730
|
return
|
715
|
-
except:
|
716
|
-
raise TequilaException(
|
731
|
+
except Exception:
|
732
|
+
raise TequilaException("could not obtain device from string; received {}".format(device))
|
717
733
|
|
718
734
|
elif isinstance(device, dict):
|
719
735
|
try:
|
720
736
|
get_qc(**device)
|
721
737
|
return
|
722
|
-
except:
|
723
|
-
raise TequilaException(
|
738
|
+
except Exception:
|
739
|
+
raise TequilaException("could not initialize device from dict; received {}".format(device))
|
724
740
|
elif isinstance(device, pyquil.api.QuantumComputer):
|
725
741
|
return
|
726
742
|
|
727
743
|
else:
|
728
744
|
raise TequilaException(
|
729
|
-
|
745
|
+
"Uninterpretable object {} of type {} passed to check_device!".format(device, type(device))
|
746
|
+
)
|
730
747
|
|
731
748
|
def retrieve_device(self, device):
|
732
749
|
"""
|
@@ -741,33 +758,35 @@ class BackendCircuitPyquil(BackendCircuit):
|
|
741
758
|
pyquil.api.QuantumComputer
|
742
759
|
an instantiated device object for pyquil simulation or execution.
|
743
760
|
"""
|
744
|
-
use_device_noise =
|
761
|
+
use_device_noise = self.noise == "device"
|
745
762
|
if device is None:
|
746
763
|
return None
|
747
764
|
if isinstance(device, str):
|
748
765
|
try:
|
749
766
|
back = get_qc(device, noisy=use_device_noise)
|
750
767
|
return back
|
751
|
-
except:
|
768
|
+
except Exception:
|
752
769
|
try:
|
753
770
|
back = get_qc(device, as_qvm=True, noisy=use_device_noise)
|
754
771
|
return back
|
755
|
-
except:
|
756
|
-
raise TequilaException(
|
772
|
+
except Exception:
|
773
|
+
raise TequilaException("could not obtain device from string; received {}".format(device))
|
757
774
|
elif isinstance(device, pyquil.api.QuantumComputer):
|
758
775
|
return device
|
759
776
|
elif isinstance(device, dict):
|
760
777
|
try:
|
761
778
|
return get_qc(**device)
|
762
|
-
except:
|
763
|
-
raise TequilaException(
|
779
|
+
except Exception:
|
780
|
+
raise TequilaException("could not initialize device from dict; received {}".format(device))
|
764
781
|
else:
|
765
782
|
raise TequilaException(
|
766
|
-
|
783
|
+
"Uninterpretable object {} of type {} passed to check_device!".format(device, type(device))
|
784
|
+
)
|
767
785
|
|
768
786
|
|
769
787
|
class BackendExpectationValuePyquil(BackendExpectationValue):
|
770
788
|
"""
|
771
789
|
See BackendExpectationValue for information.
|
772
790
|
"""
|
791
|
+
|
773
792
|
BackendCircuitType = BackendCircuitPyquil
|