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
@@ -1,5 +1,4 @@
|
|
1
|
-
from tequila.quantumchemistry.qc_base import QuantumChemistryBase, TequilaException, TequilaWarning,
|
2
|
-
QCircuit, gates
|
1
|
+
from tequila.quantumchemistry.qc_base import QuantumChemistryBase, TequilaException, TequilaWarning, QCircuit, gates
|
3
2
|
from tequila.quantumchemistry import ParametersQC, NBodyTensor
|
4
3
|
from tequila import ExpectationValue
|
5
4
|
from .chemistry_tools import OrbitalData
|
@@ -27,7 +26,6 @@ class TequilaMadnessException(TequilaException):
|
|
27
26
|
|
28
27
|
|
29
28
|
class QuantumChemistryMadness(QuantumChemistryBase):
|
30
|
-
|
31
29
|
@staticmethod
|
32
30
|
def find_executable(madness_root_dir=None):
|
33
31
|
executable = shutil.which("pno_integrals")
|
@@ -54,9 +52,10 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
54
52
|
plot2cube = shutil.which("plot2cube")
|
55
53
|
if plot2cube is None:
|
56
54
|
raise TequilaMadnessException(
|
57
|
-
"can't plot to cube file. Couldn't find plot2cube executable.\n\nTry installing\n\t conda install madtequila -c kottmann\nand assure the version is >2.3"
|
55
|
+
"can't plot to cube file. Couldn't find plot2cube executable.\n\nTry installing\n\t conda install madtequila -c kottmann\nand assure the version is >2.3"
|
56
|
+
)
|
58
57
|
|
59
|
-
if hasattr(orbital,"idx"):
|
58
|
+
if hasattr(orbital, "idx"):
|
60
59
|
idx = orbital.idx
|
61
60
|
else:
|
62
61
|
idx = self.orbitals[orbital].idx_total
|
@@ -71,23 +70,31 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
71
70
|
callist.append("{}".format(k))
|
72
71
|
|
73
72
|
import subprocess
|
73
|
+
|
74
74
|
try:
|
75
75
|
with open("plot2cube_{}.log".format(orbital), "w") as logfile:
|
76
76
|
subprocess.call(callist, stdout=logfile)
|
77
|
-
except:
|
77
|
+
except Exception:
|
78
78
|
print("plotting failed ....")
|
79
79
|
print("see plot2cube_{}.log".format(orbital))
|
80
80
|
|
81
|
-
def __init__(
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
81
|
+
def __init__(
|
82
|
+
self,
|
83
|
+
parameters: ParametersQC,
|
84
|
+
transformation: typing.Union[str, typing.Callable] = None,
|
85
|
+
active_orbitals: list = "auto",
|
86
|
+
executable: str = None,
|
87
|
+
n_pno: int = None,
|
88
|
+
n_virt: int = 0,
|
89
|
+
keep_mad_files=False,
|
90
|
+
datadir=None,
|
91
|
+
*args,
|
92
|
+
**kwargs,
|
93
|
+
):
|
94
|
+
# can not use "geometry"
|
95
|
+
# as this is already used for other things furter up
|
96
|
+
if "mad_geometry_options" in kwargs:
|
97
|
+
self.mad_geometry_options = kwargs["mad_geometry_options"]
|
91
98
|
|
92
99
|
self.datadir = datadir
|
93
100
|
|
@@ -97,9 +104,9 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
97
104
|
if executable is None:
|
98
105
|
executable = self.find_executable()
|
99
106
|
if executable is None and self.madness_root_dir is not None:
|
100
|
-
warnings.warn(
|
101
|
-
|
102
|
-
|
107
|
+
warnings.warn(
|
108
|
+
"MAD_ROOT_DIR={} found\nbut couldn't find executable".format(self.madness_root_dir), TequilaWarning
|
109
|
+
)
|
103
110
|
|
104
111
|
else:
|
105
112
|
executable = shutil.which(executable)
|
@@ -149,15 +156,18 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
149
156
|
status += str(pinfo)
|
150
157
|
|
151
158
|
solution = "Solution 1: Assuming precomputed files are available:\n provide {name}_gtensor.npy, {name}_htensor.npy and {name}_pnoinfo.txt\n and call the Molecule constructor with n_pno='read' keyword \n\nSolution 2: Try installing with conda\n conda install madtequila -c kottmann\n\nSolution 3: Install from source\n follow instructions on github.com/kottmanj/madness".format(
|
152
|
-
name=name
|
159
|
+
name=name
|
160
|
+
)
|
153
161
|
if self.executable is not None:
|
154
162
|
solution = "madness executable was found, but calculation did not succeed, check {name}_pno_integrals.out for clues".format(
|
155
|
-
name=name
|
163
|
+
name=name
|
164
|
+
)
|
156
165
|
|
157
166
|
if "failed" in h or "failed" in g:
|
158
|
-
raise TequilaMadnessException(
|
159
|
-
|
160
|
-
|
167
|
+
raise TequilaMadnessException(
|
168
|
+
"Could not initialize the madness interface\nStatus report is\n{status}\n\n".format(status=status)
|
169
|
+
+ solution
|
170
|
+
)
|
161
171
|
# get additional information from madness file
|
162
172
|
nuclear_repulsion = 0.0
|
163
173
|
pairinfo = None
|
@@ -180,7 +190,7 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
180
190
|
|
181
191
|
if pairinfo is not None:
|
182
192
|
break
|
183
|
-
except:
|
193
|
+
except Exception:
|
184
194
|
continue
|
185
195
|
|
186
196
|
if pairinfo is None:
|
@@ -196,16 +206,14 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
196
206
|
assert len(g.shape) == 4
|
197
207
|
assert len(h.shape) == 2
|
198
208
|
|
199
|
-
g = NBodyTensor(elems=g, ordering=
|
209
|
+
g = NBodyTensor(elems=g, ordering="mulliken")
|
200
210
|
|
201
211
|
orbitals = []
|
202
212
|
if pairinfo is not None:
|
203
|
-
orbitals = [OrbitalData(idx_total=i, idx=i, pair=p, occ=occinfo[i]) for i, p in
|
204
|
-
enumerate(pairinfo)]
|
213
|
+
orbitals = [OrbitalData(idx_total=i, idx=i, pair=p, occ=occinfo[i]) for i, p in enumerate(pairinfo)]
|
205
214
|
reference_orbitals = [x for x in orbitals if x.occ == 2.0]
|
206
215
|
if active_orbitals == "auto":
|
207
|
-
not_active = [i for i in reference_orbitals if
|
208
|
-
sum([1 for x in orbitals if i.idx_total in x.pair]) < 2]
|
216
|
+
not_active = [i for i in reference_orbitals if sum([1 for x in orbitals if i.idx_total in x.pair]) < 2]
|
209
217
|
active_orbitals = [x.idx_total for x in orbitals if x not in not_active]
|
210
218
|
|
211
219
|
if active_orbitals is not None:
|
@@ -222,17 +230,19 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
222
230
|
# convert to indices only
|
223
231
|
# active space data will be set in baseclass constructor
|
224
232
|
reference_orbitals = [x.idx_total for x in reference_orbitals]
|
225
|
-
super().__init__(
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
233
|
+
super().__init__(
|
234
|
+
parameters=parameters,
|
235
|
+
transformation=transformation,
|
236
|
+
active_orbitals=active_orbitals,
|
237
|
+
one_body_integrals=h,
|
238
|
+
two_body_integrals=g,
|
239
|
+
nuclear_repulsion=nuclear_repulsion,
|
240
|
+
n_orbitals=n_orbitals_total,
|
241
|
+
orbitals=orbitals,
|
242
|
+
reference_orbitals=reference_orbitals,
|
243
|
+
*args,
|
244
|
+
**kwargs,
|
245
|
+
)
|
236
246
|
|
237
247
|
# print warning if read data does not match expectations
|
238
248
|
if n_pno is not None:
|
@@ -240,24 +250,30 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
240
250
|
if n_pno + nrefs + n_virt != self.n_orbitals:
|
241
251
|
warnings.warn(
|
242
252
|
"read in data has {} pnos/virtuals, but n_pno and n_virt where set to {} and {}".format(
|
243
|
-
self.n_orbitals - nrefs, n_pno, n_virt
|
253
|
+
self.n_orbitals - nrefs, n_pno, n_virt
|
254
|
+
),
|
255
|
+
TequilaWarning,
|
256
|
+
)
|
244
257
|
|
245
258
|
# delete *.bin files and pnoinfo.txt form madness calculation
|
246
259
|
if not keep_mad_files:
|
247
260
|
self.cleanup(warn=False, delete_all_files=False)
|
248
261
|
|
249
262
|
def cleanup(self, warn=False, delete_all_files=False):
|
250
|
-
|
251
263
|
filenames = ["pnoinfo.txt", "molecule_htensor.bin", "molecule.gtensor.bin"]
|
252
264
|
if delete_all_files:
|
253
|
-
filenames = [
|
254
|
-
|
255
|
-
|
265
|
+
filenames = [
|
266
|
+
"{}_htensor.npy".format(self.parameters.name),
|
267
|
+
"{}_gtensor.npy".format(self.parameters.name),
|
268
|
+
"{}_pnoinfo.txt".format(self.parameters.name),
|
269
|
+
"{}_pno_integrals.out".format(self.parameters.name),
|
270
|
+
]
|
256
271
|
for filename in filenames:
|
257
272
|
if os.path.exists(filename):
|
258
273
|
if warn:
|
259
|
-
warnings.warn(
|
260
|
-
|
274
|
+
warnings.warn(
|
275
|
+
"Found file {} from previous calculation ... deleting it".format(filename), TequilaWarning
|
276
|
+
)
|
261
277
|
os.remove(filename)
|
262
278
|
|
263
279
|
def run_madness(self, *args, **kwargs):
|
@@ -270,6 +286,7 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
270
286
|
|
271
287
|
import subprocess
|
272
288
|
import time
|
289
|
+
|
273
290
|
start = time.time()
|
274
291
|
filename = "{}_pno_integrals.out".format(self.parameters.name)
|
275
292
|
print("Starting madness calculation with executable: ", self.executable)
|
@@ -293,18 +310,17 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
293
310
|
|
294
311
|
try:
|
295
312
|
h = numpy.load("{}_htensor.{}".format(path, filetype))
|
296
|
-
except:
|
313
|
+
except Exception:
|
297
314
|
h = "failed"
|
298
315
|
|
299
316
|
try:
|
300
317
|
g = numpy.load("{}_gtensor.{}".format(path, filetype))
|
301
|
-
except:
|
318
|
+
except Exception:
|
302
319
|
g = "failed"
|
303
320
|
|
304
321
|
return h, g
|
305
322
|
|
306
|
-
def get_pair_orbitals(self, i: OrbitalData, j: OrbitalData,
|
307
|
-
exclude: typing.List[OrbitalData] = None):
|
323
|
+
def get_pair_orbitals(self, i: OrbitalData, j: OrbitalData, exclude: typing.List[OrbitalData] = None):
|
308
324
|
if isinstance(i, int):
|
309
325
|
i = self.orbitals[i]
|
310
326
|
if isinstance(j, int):
|
@@ -349,6 +365,7 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
349
365
|
H = self.make_hamiltonian()
|
350
366
|
E = ExpectationValue(H=H, U=U)
|
351
367
|
from tequila import minimize
|
368
|
+
|
352
369
|
return minimize(objective=E, *args, **kwargs).energy
|
353
370
|
else:
|
354
371
|
return super().compute_energy(method=method, *args, **kwargs)
|
@@ -398,8 +415,18 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
398
415
|
name = "HCB-" + name
|
399
416
|
return self.make_upccgsd_ansatz(name=name, label=label)
|
400
417
|
|
401
|
-
def make_upccgsd_ansatz(
|
402
|
-
|
418
|
+
def make_upccgsd_ansatz(
|
419
|
+
self,
|
420
|
+
name="UpCCGSD",
|
421
|
+
label=None,
|
422
|
+
direct_compiling=None,
|
423
|
+
order=None,
|
424
|
+
neglect_z=None,
|
425
|
+
hcb_optimization=None,
|
426
|
+
include_reference=True,
|
427
|
+
*args,
|
428
|
+
**kwargs,
|
429
|
+
):
|
403
430
|
"""
|
404
431
|
Overwriting baseclass to allow names like : PNO-UpCCD etc
|
405
432
|
Parameters
|
@@ -422,7 +449,7 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
422
449
|
# check if the used qubit encoding has a hcb transformation
|
423
450
|
try:
|
424
451
|
have_hcb_trafo = self.transformation.hcb_to_me() is not None
|
425
|
-
except:
|
452
|
+
except Exception:
|
426
453
|
have_hcb_trafo = False
|
427
454
|
name = name.upper()
|
428
455
|
|
@@ -461,10 +488,12 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
461
488
|
if "spin_adapt_singles" not in kwargs:
|
462
489
|
kwargs["spin_adapt_singles"] = True
|
463
490
|
|
464
|
-
if direct_compiling and not have_hcb_trafo and
|
491
|
+
if direct_compiling and not have_hcb_trafo and "HCB" not in name:
|
465
492
|
raise TequilaMadnessException(
|
466
|
-
"direct_compiling={} demanded but no hcb_to_me in transformation={}\ntry transformation
|
467
|
-
direct_compiling, self.transformation
|
493
|
+
"direct_compiling={} demanded but no hcb_to_me in transformation={}\ntry transformation='ReorderedJordanWigner' ".format(
|
494
|
+
direct_compiling, self.transformation
|
495
|
+
)
|
496
|
+
)
|
468
497
|
|
469
498
|
name = name.upper()
|
470
499
|
if order is None:
|
@@ -473,16 +502,16 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
473
502
|
order = int(name.split("-")[0])
|
474
503
|
else:
|
475
504
|
order = 1
|
476
|
-
except:
|
505
|
+
except Exception:
|
477
506
|
order = 1
|
478
507
|
|
479
508
|
# first layer
|
480
509
|
U = QCircuit()
|
481
510
|
if hcb_optimization:
|
482
511
|
if "D" in excitations:
|
483
|
-
U = self.make_hardcore_boson_pno_upccd_ansatz(
|
484
|
-
|
485
|
-
|
512
|
+
U = self.make_hardcore_boson_pno_upccd_ansatz(
|
513
|
+
include_reference=include_reference, direct_compiling=direct_compiling, label=(label, 0)
|
514
|
+
)
|
486
515
|
elif include_reference:
|
487
516
|
U = self.prepare_hardcore_boson_reference()
|
488
517
|
|
@@ -501,9 +530,15 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
501
530
|
indices = self.make_upccgsd_indices(label=(label, 0), name=name, *args, **kwargs)
|
502
531
|
if include_reference:
|
503
532
|
U = self.prepare_reference()
|
504
|
-
U += self.make_upccgsd_layer(
|
505
|
-
|
506
|
-
|
533
|
+
U += self.make_upccgsd_layer(
|
534
|
+
indices=indices,
|
535
|
+
include_singles="S" in excitations,
|
536
|
+
include_doubles="D" in excitations,
|
537
|
+
label=(label, 0),
|
538
|
+
neglect_z=neglect_z,
|
539
|
+
*args,
|
540
|
+
**kwargs,
|
541
|
+
)
|
507
542
|
|
508
543
|
if order > 1:
|
509
544
|
for layer in range(1, order):
|
@@ -511,13 +546,20 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
511
546
|
if "HCB" in name:
|
512
547
|
U += self.make_hardcore_boson_upccgd_layer(indices=indices, label=(label, layer), *args, **kwargs)
|
513
548
|
else:
|
514
|
-
U += self.make_upccgsd_layer(
|
515
|
-
|
516
|
-
|
549
|
+
U += self.make_upccgsd_layer(
|
550
|
+
indices=indices,
|
551
|
+
include_singles="S" in excitations,
|
552
|
+
include_doubles="D" in excitations,
|
553
|
+
label=(label, layer),
|
554
|
+
neglect_z=neglect_z,
|
555
|
+
*args,
|
556
|
+
**kwargs,
|
557
|
+
)
|
517
558
|
return U
|
518
559
|
|
519
|
-
def make_hardcore_boson_pno_upccd_ansatz(
|
520
|
-
|
560
|
+
def make_hardcore_boson_pno_upccd_ansatz(
|
561
|
+
self, pairs=None, label=None, include_reference=True, direct_compiling=False
|
562
|
+
):
|
521
563
|
if pairs is None:
|
522
564
|
pairs = [x for x in self.reference_orbitals]
|
523
565
|
U = QCircuit()
|
@@ -613,8 +655,7 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
613
655
|
indices.append(idx)
|
614
656
|
return indices
|
615
657
|
|
616
|
-
def make_pno_upccgsd_ansatz(self, generalized=False, include_offdiagonals=False,
|
617
|
-
**kwargs):
|
658
|
+
def make_pno_upccgsd_ansatz(self, generalized=False, include_offdiagonals=False, **kwargs):
|
618
659
|
indices = []
|
619
660
|
refs = self.reference_orbitals
|
620
661
|
for i in self.reference_orbitals:
|
@@ -645,14 +686,15 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
645
686
|
|
646
687
|
return self.make_upccgsd_ansatz(indices=indices, **kwargs)
|
647
688
|
|
648
|
-
def write_madness_input(
|
649
|
-
|
650
|
-
|
689
|
+
def write_madness_input(
|
690
|
+
self, n_pno=None, n_virt=0, filename="input", maxrank=None, n_orbitals=None, *args, **kwargs
|
691
|
+
):
|
651
692
|
if n_pno is not None and n_orbitals is not None:
|
652
693
|
raise TequilaMadnessException(
|
653
|
-
"n_pno={} and n_orbitals={} given ... please pick one".format(n_pno, n_orbitals)
|
694
|
+
"n_pno={} and n_orbitals={} given ... please pick one".format(n_pno, n_orbitals)
|
695
|
+
)
|
654
696
|
|
655
|
-
n_electrons = self.parameters.
|
697
|
+
n_electrons = self.parameters.total_n_electrons
|
656
698
|
if self.parameters.frozen_core:
|
657
699
|
# only count active electrons (will not compute pnos for frozen pairs)
|
658
700
|
n_core_electrons = self.parameters.get_number_of_core_electrons()
|
@@ -667,23 +709,34 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
667
709
|
|
668
710
|
if maxrank is None:
|
669
711
|
# need at least maxrank=1, otherwise no PNOs are computed
|
670
|
-
# this was a bug in <=v1.8.5
|
671
|
-
maxrank = max(1, int(numpy.ceil(n_pno
|
712
|
+
# this was a bug in <=v1.8.5
|
713
|
+
maxrank = max(1, int(numpy.ceil(n_pno / n_pairs)))
|
672
714
|
|
673
715
|
if maxrank <= 0:
|
674
716
|
warnings.warn(
|
675
|
-
|
676
|
-
maxrank
|
717
|
+
'maxrank={} in tequila madness backend! No PNOs will be computed. Set the value when initializing the Molecule as tq.Molecule(..., pno={"maxrank":1, ...})'.format(
|
718
|
+
maxrank
|
719
|
+
),
|
720
|
+
TequilaWarning,
|
721
|
+
)
|
677
722
|
|
678
723
|
data = {}
|
679
724
|
if self.parameters.multiplicity != 1:
|
680
725
|
raise TequilaMadnessException(
|
681
726
|
"Currently only closed shell supported for MRA-PNO-MP2, you demanded multiplicity={} for the surrogate".format(
|
682
|
-
self.parameters.multiplicity
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
727
|
+
self.parameters.multiplicity
|
728
|
+
)
|
729
|
+
)
|
730
|
+
data["dft"] = {
|
731
|
+
"charge": self.parameters.charge,
|
732
|
+
"xc": "hf",
|
733
|
+
"k": 7,
|
734
|
+
"econv": 1.0e-4,
|
735
|
+
"dconv": 5.0e-4,
|
736
|
+
"localize": "boys",
|
737
|
+
"ncf": "( none , 1.0 )",
|
738
|
+
}
|
739
|
+
data["pno"] = {"maxrank": maxrank, "f12": "false", "thresh": 1.0e-4, "diagonal": True}
|
687
740
|
if not self.parameters.frozen_core:
|
688
741
|
data["pno"]["freeze"] = 0
|
689
742
|
data["pnoint"] = {"n_pno": n_pno, "n_virt": n_virt, "orthog": "symmetric"}
|
@@ -693,6 +746,16 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
693
746
|
if key in kwargs:
|
694
747
|
data[key] = {**data[key], **kwargs[key]}
|
695
748
|
|
749
|
+
geom = {}
|
750
|
+
if hasattr(self, "mad_geometry_options"):
|
751
|
+
geom = self.mad_geometry_options
|
752
|
+
|
753
|
+
if "units" not in geom:
|
754
|
+
geom["units"] = "angstrom"
|
755
|
+
if "eprec" not in geom:
|
756
|
+
geom["eprec"] = 1.0e-6
|
757
|
+
if "no_orient" not in geom:
|
758
|
+
geom["no_orient"] = 1
|
696
759
|
if filename is not None:
|
697
760
|
with open(filename, "w") as f:
|
698
761
|
for k1, v1 in data.items():
|
@@ -702,8 +765,8 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
702
765
|
print("end\n", file=f)
|
703
766
|
|
704
767
|
print("geometry", file=f)
|
705
|
-
|
706
|
-
|
768
|
+
for k, v in geom.items():
|
769
|
+
print("{} {}".format(k, v), file=f)
|
707
770
|
for line in self.parameters.get_geometry_string().split("\n"):
|
708
771
|
line = line.strip()
|
709
772
|
if line != "":
|
@@ -718,6 +781,7 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
718
781
|
# if the datadir does not exist then tequila will crash
|
719
782
|
try:
|
720
783
|
import os
|
784
|
+
|
721
785
|
if not os.path.exists(datadir):
|
722
786
|
os.makedirs(datadir)
|
723
787
|
except Exception as E:
|
@@ -727,7 +791,7 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
727
791
|
try:
|
728
792
|
g_data = numpy.fromfile("molecule_gtensor.bin".format())
|
729
793
|
sd = int(numpy.power(g_data.size, 0.25))
|
730
|
-
assert
|
794
|
+
assert sd**4 == g_data.size
|
731
795
|
sds = [sd] * 4
|
732
796
|
g = g_data.reshape(sds)
|
733
797
|
numpy.save("{}_gtensor.npy".format(path), arr=g)
|
@@ -737,7 +801,7 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
737
801
|
try:
|
738
802
|
h_data = numpy.fromfile("molecule_htensor.bin")
|
739
803
|
sd = int(numpy.sqrt(h_data.size))
|
740
|
-
assert
|
804
|
+
assert sd**2 == h_data.size
|
741
805
|
sds = [sd] * 2
|
742
806
|
h = h_data.reshape(sds)
|
743
807
|
numpy.save("{}_htensor.npy".format(path), arr=h)
|
@@ -757,16 +821,24 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
757
821
|
except Exception as E:
|
758
822
|
pnoinfo = "failed\n{}\n".format(str(E))
|
759
823
|
try:
|
760
|
-
with
|
761
|
-
|
824
|
+
with (
|
825
|
+
open("{}_pno_integrals.out".format(name), "r") as f1,
|
826
|
+
open("{}_pno_integrals.out".format(path), "w") as f2,
|
827
|
+
):
|
762
828
|
f2.write(f1.read().strip())
|
763
829
|
except Exception as E:
|
764
830
|
pass
|
765
831
|
|
766
832
|
return h, g, pnoinfo
|
767
833
|
|
768
|
-
def perturbative_f12_correction(
|
769
|
-
|
834
|
+
def perturbative_f12_correction(
|
835
|
+
self,
|
836
|
+
rdm1: numpy.ndarray = None,
|
837
|
+
rdm2: numpy.ndarray = None,
|
838
|
+
n_ri: int = None,
|
839
|
+
f12_filename: str = "molecule_f12tensor.bin",
|
840
|
+
**kwargs,
|
841
|
+
) -> float:
|
770
842
|
"""
|
771
843
|
Computes the spin-free [2]_R12 correction, needing only the 1- and 2-RDM of a reference method
|
772
844
|
Requires either 1-RDM, 2-RDM or information to compute them in kwargs
|
@@ -793,8 +865,10 @@ class QuantumChemistryMadness(QuantumChemistryBase):
|
|
793
865
|
the f12 correction for the energy
|
794
866
|
"""
|
795
867
|
from .f12_corrections._f12_correction_madness import ExplicitCorrelationCorrectionMadness
|
796
|
-
|
797
|
-
|
868
|
+
|
869
|
+
correction = ExplicitCorrelationCorrectionMadness(
|
870
|
+
mol=self, rdm1=rdm1, rdm2=rdm2, n_ri=n_ri, f12_filename=f12_filename, **kwargs
|
871
|
+
)
|
798
872
|
|
799
873
|
return correction.compute()
|
800
874
|
|