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.
Files changed (86) hide show
  1. tequila/__init__.py +29 -14
  2. tequila/apps/__init__.py +14 -5
  3. tequila/apps/_unary_state_prep_impl.py +145 -112
  4. tequila/apps/adapt/__init__.py +9 -1
  5. tequila/apps/adapt/adapt.py +154 -113
  6. tequila/apps/krylov/__init__.py +1 -1
  7. tequila/apps/krylov/krylov.py +23 -21
  8. tequila/apps/robustness/helpers.py +10 -6
  9. tequila/apps/robustness/interval.py +238 -156
  10. tequila/apps/unary_state_prep.py +29 -23
  11. tequila/autograd_imports.py +8 -5
  12. tequila/circuit/__init__.py +2 -1
  13. tequila/circuit/_gates_impl.py +135 -67
  14. tequila/circuit/circuit.py +163 -79
  15. tequila/circuit/compiler.py +114 -105
  16. tequila/circuit/gates.py +288 -120
  17. tequila/circuit/gradient.py +35 -23
  18. tequila/circuit/noise.py +83 -74
  19. tequila/circuit/postselection.py +120 -0
  20. tequila/circuit/pyzx.py +10 -6
  21. tequila/circuit/qasm.py +201 -83
  22. tequila/circuit/qpic.py +63 -61
  23. tequila/grouping/binary_rep.py +148 -146
  24. tequila/grouping/binary_utils.py +84 -75
  25. tequila/grouping/compile_groups.py +334 -230
  26. tequila/grouping/ev_utils.py +77 -41
  27. tequila/grouping/fermionic_functions.py +383 -308
  28. tequila/grouping/fermionic_methods.py +170 -123
  29. tequila/grouping/overlapping_methods.py +69 -52
  30. tequila/hamiltonian/paulis.py +12 -13
  31. tequila/hamiltonian/paulistring.py +1 -1
  32. tequila/hamiltonian/qubit_hamiltonian.py +45 -35
  33. tequila/ml/__init__.py +1 -0
  34. tequila/ml/interface_torch.py +19 -16
  35. tequila/ml/ml_api.py +11 -10
  36. tequila/ml/utils_ml.py +12 -11
  37. tequila/objective/__init__.py +8 -3
  38. tequila/objective/braket.py +55 -47
  39. tequila/objective/objective.py +87 -55
  40. tequila/objective/qtensor.py +36 -27
  41. tequila/optimizers/__init__.py +31 -23
  42. tequila/optimizers/_containers.py +11 -7
  43. tequila/optimizers/optimizer_base.py +111 -83
  44. tequila/optimizers/optimizer_gd.py +258 -231
  45. tequila/optimizers/optimizer_gpyopt.py +56 -42
  46. tequila/optimizers/optimizer_scipy.py +157 -112
  47. tequila/quantumchemistry/__init__.py +66 -38
  48. tequila/quantumchemistry/chemistry_tools.py +393 -209
  49. tequila/quantumchemistry/encodings.py +121 -13
  50. tequila/quantumchemistry/madness_interface.py +170 -96
  51. tequila/quantumchemistry/orbital_optimizer.py +86 -41
  52. tequila/quantumchemistry/psi4_interface.py +166 -97
  53. tequila/quantumchemistry/pyscf_interface.py +70 -23
  54. tequila/quantumchemistry/qc_base.py +866 -414
  55. tequila/simulators/__init__.py +0 -3
  56. tequila/simulators/simulator_api.py +247 -105
  57. tequila/simulators/simulator_aqt.py +102 -0
  58. tequila/simulators/simulator_base.py +147 -53
  59. tequila/simulators/simulator_cirq.py +58 -42
  60. tequila/simulators/simulator_cudaq.py +600 -0
  61. tequila/simulators/simulator_ddsim.py +390 -0
  62. tequila/simulators/simulator_mqp.py +30 -0
  63. tequila/simulators/simulator_pyquil.py +190 -171
  64. tequila/simulators/simulator_qibo.py +95 -87
  65. tequila/simulators/simulator_qiskit.py +119 -107
  66. tequila/simulators/simulator_qlm.py +52 -26
  67. tequila/simulators/simulator_qulacs.py +74 -52
  68. tequila/simulators/simulator_spex.py +95 -60
  69. tequila/simulators/simulator_symbolic.py +6 -5
  70. tequila/simulators/test_spex_simulator.py +8 -11
  71. tequila/tools/convenience.py +4 -4
  72. tequila/tools/qng.py +72 -64
  73. tequila/tools/random_generators.py +38 -34
  74. tequila/utils/bitstrings.py +7 -7
  75. tequila/utils/exceptions.py +19 -5
  76. tequila/utils/joined_transformation.py +8 -10
  77. tequila/utils/keymap.py +0 -5
  78. tequila/utils/misc.py +6 -4
  79. tequila/version.py +1 -1
  80. tequila/wavefunction/qubit_wavefunction.py +47 -28
  81. {tequila_basic-1.9.9.dist-info → tequila_basic-1.9.10.dist-info}/METADATA +13 -16
  82. tequila_basic-1.9.10.dist-info/RECORD +93 -0
  83. {tequila_basic-1.9.9.dist-info → tequila_basic-1.9.10.dist-info}/WHEEL +1 -1
  84. tequila_basic-1.9.9.dist-info/RECORD +0 -88
  85. {tequila_basic-1.9.9.dist-info → tequila_basic-1.9.10.dist-info}/licenses/LICENSE +0 -0
  86. {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, numbers
10
+ import typing
11
+ import numbers
11
12
 
12
13
  import cirq
13
14
  import cirq_google
14
15
 
15
- map_1 = lambda x: {'exponent': x}
16
- map_2 = lambda x: {'exponent': x / np.pi, 'global_shift': -0.5}
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
- 'I': (cirq.ops.IdentityGate, None),
117
- 'X': (cirq.ops.common_gates.XPowGate, map_1),
118
- 'Y': (cirq.ops.common_gates.YPowGate, map_1),
119
- 'Z': (cirq.ops.common_gates.ZPowGate, map_1),
120
- 'H': (cirq.ops.common_gates.HPowGate, map_1),
121
- 'Rx': (cirq.ops.common_gates.XPowGate, map_2),
122
- 'Ry': (cirq.ops.common_gates.YPowGate, map_2),
123
- 'Rz': (cirq.ops.common_gates.ZPowGate, map_2),
124
- 'SWAP': (cirq.ops.SwapPowGate, None),
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['cc_max'] = True
131
- super().__init__(abstract_circuit=abstract_circuit, variables=variables,
132
- noise=noise, qubit_map=qubit_map, device=device, *args, **kwargs)
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 == 'device':
143
- raise TequilaException('cannot get device noise for cirq yet, sorry!')
150
+ if self.noise == "device":
151
+ raise TequilaException("cannot get device noise for cirq yet, sorry!")
144
152
  self.noise_lookup = {
145
- 'bit flip': [lambda x: cirq.bit_flip(x)],
146
- 'phase flip': [lambda x: cirq.phase_flip(x)],
147
- 'phase damp': [cirq.phase_damp],
148
- 'amplitude damp': [cirq.amplitude_damp],
149
- 'phase-amplitude damp': [cirq.amplitude_damp, cirq.phase_damp],
150
- 'depolarizing': [lambda x: cirq.depolarize(p=(3 / 4) * x)]
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(program=self.circuit, param_resolver=self.resolver,
175
- initial_state=initial_state)
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 (len(backend_result.measurements) == 1)
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(cirq.sample(program=circuit, param_resolver=self.resolver, repetitions=samples))
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, 'power'):
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('{}_{}'.format(self._name_variable_objective(parameter), str(self.counter)))
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 # avoid inplace operations for measurements
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('cirq_google')
362
- assert HAS_GOOGLE, TequilaCirqException(' cirq_google package is not installed.')
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('original message:\n{}\n\ncould not optimize for device={}'.format(original_message,device))
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('Only Sycamore and Sycamore23 devices currently functional. Sorry!')
385
+ raise TequilaException("Only Sycamore and Sycamore23 devices currently functional. Sorry!")
373
386
 
374
387
  else:
375
388
  raise TequilaException(
376
- 'build_device_circuit demands a cirq.Device object; received {}, of type {}'.format(str(device),
377
- type(device)))
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('Unable to retrieve requested device, {}, in cirq'.format(str(device)))
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 ['sycamore', 'sycamore23']:
482
+ if device.lower() in ["sycamore", "sycamore23"]:
468
483
  pass
469
484
  else:
470
- raise TequilaException('requested device {} could not be found!'.format(device))
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