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
@@ -1,7 +1,9 @@
1
- import numpy, typing
1
+ import numpy
2
+ import typing
2
3
  from .objective import Objective, ExpectationValueImpl, format_variable_dictionary
3
4
  from tequila import TequilaException
4
5
 
6
+
5
7
  class QTensor(numpy.ndarray):
6
8
  # see here: https://numpy.org/devdocs/user/basics.subclassing.html
7
9
 
@@ -15,17 +17,17 @@ class QTensor(numpy.ndarray):
15
17
  # do all-zero initialization
16
18
  shape = self.shape
17
19
  if objective_list is None:
18
- with numpy.nditer(self, flags =["refs_ok"], op_flags=['readwrite']) as it:
20
+ with numpy.nditer(self, flags=["refs_ok"], op_flags=["readwrite"]) as it:
19
21
  for x in it:
20
22
  x[...] = Objective()
21
23
  else:
22
- j=0
23
- with numpy.nditer(self, flags =["refs_ok"], op_flags=['readwrite']) as it:
24
+ j = 0
25
+ with numpy.nditer(self, flags=["refs_ok"], op_flags=["readwrite"]) as it:
24
26
  for x in it:
25
27
  x[...] = objective_list[j]
26
- j=j+1
28
+ j = j + 1
27
29
 
28
- def __call__(self,variables=None, *args, **kwargs):
30
+ def __call__(self, variables=None, *args, **kwargs):
29
31
  """
30
32
  Return the output of the calculation the objective represents.
31
33
 
@@ -45,13 +47,15 @@ class QTensor(numpy.ndarray):
45
47
  # failsafe
46
48
  check_variables = {k: k in variables for k in self.extract_variables()}
47
49
  if not all(list(check_variables.values())):
48
- raise TequilaException("Objective did not receive all variables:\n"
49
- "You gave\n"
50
- " {}\n"
51
- " but the objective depends on\n"
52
- " {}\n"
53
- " missing values for\n"
54
- " {}".format(variables, self.extract_variables(), [k for k,v in check_variables.items() if not v]))
50
+ raise TequilaException(
51
+ "Objective did not receive all variables:\n"
52
+ "You gave\n"
53
+ " {}\n"
54
+ " but the objective depends on\n"
55
+ " {}\n"
56
+ " missing values for\n"
57
+ " {}".format(variables, self.extract_variables(), [k for k, v in check_variables.items() if not v])
58
+ )
55
59
 
56
60
  # avoid multiple evaluations
57
61
  evaluated = {}
@@ -60,7 +64,7 @@ class QTensor(numpy.ndarray):
60
64
  for obj in newtensor:
61
65
  a = obj(variables=variables, *args, **kwargs)
62
66
  ev_array.append(a)
63
- ev_array = numpy.reshape(ev_array,self.shape)
67
+ ev_array = numpy.reshape(ev_array, self.shape)
64
68
  if ev_array.shape == ():
65
69
  return float(ev_array)
66
70
  elif len(ev_array) == 1:
@@ -73,11 +77,11 @@ class QTensor(numpy.ndarray):
73
77
  _fn = numpy.vectorize(_f)
74
78
  return _fn(self)
75
79
 
76
- def extract_variables(self)->list:
80
+ def extract_variables(self) -> list:
77
81
  newtensor = self.flatten()
78
82
  unique = []
79
83
  for obj in newtensor:
80
- if hasattr(obj, 'extract_variables'):
84
+ if hasattr(obj, "extract_variables"):
81
85
  var_list = obj.extract_variables()
82
86
  for j in var_list:
83
87
  if j not in unique:
@@ -94,7 +98,7 @@ class QTensor(numpy.ndarray):
94
98
  newtensor = self.flatten()
95
99
  expvals = []
96
100
  for obj in newtensor:
97
- if hasattr(obj, 'get_expectationvalues'):
101
+ if hasattr(obj, "get_expectationvalues"):
98
102
  expvals += obj.get_expectationvalues()
99
103
  return expvals
100
104
 
@@ -129,7 +133,7 @@ class QTensor(numpy.ndarray):
129
133
  return len(self.get_expectationvalues())
130
134
 
131
135
  def __repr__(self):
132
- _repmat = numpy.empty(self.shape,dtype = object)
136
+ _repmat = numpy.empty(self.shape, dtype=object)
133
137
  _repmat = _repmat.flatten()
134
138
  newtensor = self.flatten()
135
139
  for i in range(len(newtensor)):
@@ -144,7 +148,7 @@ class QTensor(numpy.ndarray):
144
148
  newtensor = self.flatten()
145
149
  types = []
146
150
  for obj in newtensor:
147
- if hasattr(obj, 'get_expectationvalues'):
151
+ if hasattr(obj, "get_expectationvalues"):
148
152
  _types = [type(E) for E in obj.get_expectationvalues()]
149
153
  for tt in _types:
150
154
  types.append(tt)
@@ -157,20 +161,21 @@ class QTensor(numpy.ndarray):
157
161
 
158
162
  unique = self.count_expectationvalues(unique=True)
159
163
  measurements = self.count_measurements()
160
- return "QTensor of shape {} with {} unique expectation values\n" \
161
- "total measurements = {}\n" \
162
- "variables = {}\n" \
163
- "types = {}".format(self.shape, unique, measurements, variables, types)
164
+ return (
165
+ "QTensor of shape {} with {} unique expectation values\n"
166
+ "total measurements = {}\n"
167
+ "variables = {}\n"
168
+ "types = {}".format(self.shape, unique, measurements, variables, types)
169
+ )
164
170
 
165
171
  def contract(self):
166
172
  newtensor = self.flatten()
167
- out_array=[obj for obj in newtensor]
173
+ out_array = [obj for obj in newtensor]
168
174
  summed = out_array[0]
169
175
  for entry in out_array[1:]:
170
176
  summed += entry
171
177
  return summed
172
178
 
173
-
174
179
  class HelperObject:
175
180
  """
176
181
  This is a small helper object class for tequila objectives
@@ -178,17 +183,21 @@ class QTensor(numpy.ndarray):
178
183
  create if like this:
179
184
  ff = HelperObject(func=f) where f is the function you want to apply later (e.g. numpy.sin)
180
185
  use if like this with tequila objectives
181
- f_on_objective = ff(objective)
186
+ f_on_objective = ff(objective)
182
187
  """
188
+
183
189
  def __init__(self, func):
184
190
  self.func = func
191
+
185
192
  def __call__(self, objective):
186
193
  return objective.apply(self.func)
187
194
 
195
+
188
196
  # ------------------------------------------------------
189
197
  # backward compatibility with old VectorObjective class
190
198
  # ------------------------------------------------------
191
199
 
200
+
192
201
  def vectorize(objectives):
193
202
  """
194
203
  Combine several objectives in order, into one longer vector.
@@ -206,6 +215,7 @@ def vectorize(objectives):
206
215
  """
207
216
  return QTensor(objective_list=objectives, shape=(len(objectives),))
208
217
 
218
+
209
219
  def VectorObjective(argsets: typing.Iterable = None, transformations: typing.Iterable[callable] = None):
210
220
  if argsets is None:
211
221
  return QTensor()
@@ -219,4 +229,3 @@ def VectorObjective(argsets: typing.Iterable = None, transformations: typing.Ite
219
229
  objective_list.append(Objective(args=argsets[i], transformation=transformations[i]))
220
230
 
221
231
  return vectorize(objectives=objective_list)
222
-
@@ -6,7 +6,9 @@ from tequila.optimizers.optimizer_gd import minimize as minimize_gd
6
6
  from tequila.simulators.simulator_api import simulate
7
7
  from dataclasses import dataclass
8
8
 
9
- import typing, numbers, numpy
9
+ import typing
10
+ import numbers
11
+ import numpy
10
12
 
11
13
 
12
14
  @dataclass
@@ -16,27 +18,26 @@ class _Optimizers:
16
18
  methods: list = None
17
19
 
18
20
 
19
- SUPPORTED_OPTIMIZERS = ['scipy', 'gpyopt', 'gd']
21
+ SUPPORTED_OPTIMIZERS = ["scipy", "gpyopt", "gd"]
20
22
  INSTALLED_OPTIMIZERS = {}
21
- INSTALLED_OPTIMIZERS['scipy'] = _Optimizers(cls=OptimizerSciPy,
22
- minimize=minimize_scipy,
23
- methods=OptimizerSciPy.available_methods())
24
- INSTALLED_OPTIMIZERS['gd'] = _Optimizers(cls=OptimizerGD,
25
- minimize=minimize_gd,
26
- methods=OptimizerGD.available_methods())
23
+ INSTALLED_OPTIMIZERS["scipy"] = _Optimizers(
24
+ cls=OptimizerSciPy, minimize=minimize_scipy, methods=OptimizerSciPy.available_methods()
25
+ )
26
+ INSTALLED_OPTIMIZERS["gd"] = _Optimizers(cls=OptimizerGD, minimize=minimize_gd, methods=OptimizerGD.available_methods())
27
27
 
28
28
  has_gpyopt = False
29
29
  try:
30
30
  from tequila.optimizers.optimizer_gpyopt import OptimizerGPyOpt
31
31
  from tequila.optimizers.optimizer_gpyopt import minimize as minimize_gpyopt
32
32
 
33
- INSTALLED_OPTIMIZERS['gpyopt'] = _Optimizers(cls=OptimizerGPyOpt,
34
- minimize=minimize_gpyopt,
35
- methods=OptimizerGPyOpt.available_methods())
33
+ INSTALLED_OPTIMIZERS["gpyopt"] = _Optimizers(
34
+ cls=OptimizerGPyOpt, minimize=minimize_gpyopt, methods=OptimizerGPyOpt.available_methods()
35
+ )
36
36
  has_gpyopt = True
37
37
  except ImportError:
38
38
  has_gpyopt = False
39
39
 
40
+
40
41
  def show_available_optimizers(module=None):
41
42
  """
42
43
  Returns
@@ -65,13 +66,15 @@ def show_available_optimizers(module=None):
65
66
  print("Installed optimizer modules: ", list(INSTALLED_OPTIMIZERS.keys()))
66
67
 
67
68
 
68
- def minimize(objective,
69
- method: str = "bfgs",
70
- variables: list = None,
71
- initial_values: typing.Union[dict, numbers.Number, typing.Callable] = 0.0,
72
- maxiter: int = None,
73
- *args,
74
- **kwargs):
69
+ def minimize(
70
+ objective,
71
+ method: str = "bfgs",
72
+ variables: list = None,
73
+ initial_values: typing.Union[dict, numbers.Number, typing.Callable] = 0.0,
74
+ maxiter: int = None,
75
+ *args,
76
+ **kwargs,
77
+ ):
75
78
  """
76
79
 
77
80
  Parameters
@@ -115,10 +118,12 @@ def minimize(objective,
115
118
 
116
119
  """
117
120
 
118
- ovtmp=objective.extract_variables()
119
- fast_return=False
121
+ ovtmp = objective.extract_variables()
122
+ fast_return = False
120
123
  if ovtmp is None or len(ovtmp) == 0:
121
- return OptimizerResults(energy=float(simulate(objective, *args, **kwargs)), variables={}, history=OptimizerHistory())
124
+ return OptimizerResults(
125
+ energy=float(simulate(objective, *args, **kwargs)), variables={}, history=OptimizerHistory()
126
+ )
122
127
 
123
128
  for k, v in INSTALLED_OPTIMIZERS.items():
124
129
  if method.lower() in v.methods or method.upper() in v.methods:
@@ -128,7 +133,10 @@ def minimize(objective,
128
133
  variables=variables,
129
134
  initial_values=initial_values,
130
135
  maxiter=maxiter,
131
- *args, **kwargs)
136
+ *args,
137
+ **kwargs,
138
+ )
132
139
 
133
140
  raise TequilaOptimizerException(
134
- "Could not find optimization method {} in tequila optimizers. You might miss dependencies")
141
+ "Could not find optimization method {} in tequila optimizers. You might miss dependencies"
142
+ )
@@ -2,12 +2,12 @@ import numpy
2
2
  from tequila.objective import format_variable_dictionary
3
3
  from tequila.tools.qng import evaluate_qng
4
4
  import sys
5
+
5
6
  """
6
7
  Define Containers for SciPy usage
7
8
  """
8
9
 
9
10
 
10
-
11
11
  class _EvalContainer:
12
12
  """
13
13
  Container Class to access scipy and keep the optimization history.
@@ -35,8 +35,9 @@ class _EvalContainer:
35
35
 
36
36
  """
37
37
 
38
- def __init__(self, objective, param_keys, passive_angles=None, samples=None, save_history=True,
39
- print_level: int = 3):
38
+ def __init__(
39
+ self, objective, param_keys, passive_angles=None, samples=None, save_history=True, print_level: int = 3
40
+ ):
40
41
  self.objective = objective
41
42
  self.samples = samples
42
43
  self.param_keys = param_keys
@@ -135,11 +136,14 @@ class _QngContainer(_EvalContainer):
135
136
  evaluate the qng.
136
137
  """
137
138
 
138
-
139
139
  def __init__(self, combos, param_keys, passive_angles=None, samples=None, save_history=True):
140
-
141
- super().__init__(objective=None, param_keys=param_keys, passive_angles=passive_angles,
142
- samples=samples, save_history=save_history)
140
+ super().__init__(
141
+ objective=None,
142
+ param_keys=param_keys,
143
+ passive_angles=passive_angles,
144
+ samples=samples,
145
+ save_history=save_history,
146
+ )
143
147
 
144
148
  self.combos = combos
145
149