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,9 +1,37 @@
|
|
1
|
-
from tequila import TequilaException
|
1
|
+
from tequila import TequilaException, QubitWaveFunction
|
2
2
|
from tequila.quantumchemistry.qc_base import QuantumChemistryBase
|
3
3
|
from tequila.quantumchemistry import ParametersQC, NBodyTensor
|
4
4
|
import pyscf
|
5
5
|
|
6
|
-
import
|
6
|
+
from .chemistry_tools import OrbitalData
|
7
|
+
|
8
|
+
import numpy
|
9
|
+
import typing
|
10
|
+
|
11
|
+
|
12
|
+
def _merge_alpha_beta_strs(alpha_str, beta_str, norb):
|
13
|
+
"""
|
14
|
+
Merge alpha and beta bitstrings into a single string and compute the resulting phase.
|
15
|
+
|
16
|
+
Args:
|
17
|
+
alpha_str (int): Bitstring representing alpha electrons.
|
18
|
+
beta_str (int): Bitstring representing beta electrons.
|
19
|
+
norb (int): Number of orbitals.
|
20
|
+
|
21
|
+
Returns:
|
22
|
+
tuple:
|
23
|
+
merged_str (int): Interleaved bitstring.
|
24
|
+
phase (int): Phase factor (+1 or -1) from fermionic antisymmetry.
|
25
|
+
"""
|
26
|
+
# Interleave the alpha and beta strings
|
27
|
+
alpha_str_b = bin(alpha_str)[2:].zfill(norb)
|
28
|
+
beta_str_b = bin(beta_str)[2:].zfill(norb)
|
29
|
+
merged_str = "".join([alpha_str_b[i] + beta_str_b[i] for i in range(norb)])[::-1]
|
30
|
+
|
31
|
+
# Position of filled orbitals
|
32
|
+
set_bits_beta = [i for i in range(norb) if (beta_str >> i) & 1]
|
33
|
+
phase = (-1) ** sum([(alpha_str & 2**i - 1).bit_count() for i in set_bits_beta])
|
34
|
+
return int(merged_str, 2), phase
|
7
35
|
|
8
36
|
|
9
37
|
class OpenVQEEPySCFException(TequilaException):
|
@@ -11,12 +39,11 @@ class OpenVQEEPySCFException(TequilaException):
|
|
11
39
|
|
12
40
|
|
13
41
|
class QuantumChemistryPySCF(QuantumChemistryBase):
|
14
|
-
def __init__(
|
15
|
-
|
16
|
-
|
17
|
-
|
42
|
+
def __init__(
|
43
|
+
self, parameters: ParametersQC, transformation: typing.Union[str, typing.Callable] = None, *args, **kwargs
|
44
|
+
):
|
45
|
+
orbitals = None
|
18
46
|
if "one_body_integrals" not in kwargs:
|
19
|
-
|
20
47
|
geometry = parameters.get_geometry()
|
21
48
|
pyscf_geomstring = ""
|
22
49
|
for atom in geometry:
|
@@ -51,20 +78,23 @@ class QuantumChemistryPySCF(QuantumChemistryBase):
|
|
51
78
|
|
52
79
|
mf.kernel()
|
53
80
|
|
54
|
-
|
55
|
-
|
56
|
-
# irrep information is however not critical to tequila
|
57
|
-
if hasattr(mf, "get_irrep_nelec"):
|
58
|
-
self.irreps = mf.get_irrep_nelec()
|
59
|
-
else:
|
60
|
-
self.irreps = None
|
61
|
-
|
81
|
+
self.irreps = pyscf.symm.label_orb_symm(mol, mol.irrep_name, mol.symm_orb, mf.mo_coeff).tolist()
|
82
|
+
|
62
83
|
orbital_energies = mf.mo_energy
|
63
84
|
|
85
|
+
orbitals = [
|
86
|
+
OrbitalData(idx_total=idx, irrep=irr, energy=energy)
|
87
|
+
for idx, (irr, energy) in enumerate(zip(self.irreps, orbital_energies))
|
88
|
+
]
|
89
|
+
|
90
|
+
for irr in {o.irrep for o in orbitals}:
|
91
|
+
for i, o in enumerate([o for o in orbitals if o.irrep == irr]):
|
92
|
+
o.idx_irrep = i
|
93
|
+
|
64
94
|
# compute mo integrals
|
65
95
|
mo_coeff = mf.mo_coeff
|
66
|
-
h_ao = mol.intor(
|
67
|
-
g_ao = mol.intor(
|
96
|
+
h_ao = mol.intor("int1e_kin") + mol.intor("int1e_nuc")
|
97
|
+
g_ao = mol.intor("int2e", aosym="s1")
|
68
98
|
S = mol.intor_symmetric("int1e_ovlp")
|
69
99
|
g_ao = NBodyTensor(elems=g_ao, ordering="mulliken")
|
70
100
|
|
@@ -80,14 +110,27 @@ class QuantumChemistryPySCF(QuantumChemistryBase):
|
|
80
110
|
if "nuclear_repulsion" not in kwargs:
|
81
111
|
kwargs["nuclear_repulsion"] = mol.energy_nuc()
|
82
112
|
|
83
|
-
super().__init__(parameters=parameters, transformation=transformation, *args, **kwargs)
|
113
|
+
super().__init__(parameters=parameters, transformation=transformation, orbitals=orbitals, *args, **kwargs)
|
84
114
|
|
85
|
-
def compute_fci(self,
|
115
|
+
def compute_fci(self, get_wfn=False, **kwargs):
|
86
116
|
from pyscf import fci
|
117
|
+
|
87
118
|
c, h1, h2 = self.get_integrals(ordering="chem")
|
88
119
|
norb = self.n_orbitals
|
89
120
|
nelec = self.n_electrons
|
90
121
|
e, fcivec = fci.direct_spin1.kernel(h1, h2.elems, norb, nelec, **kwargs)
|
122
|
+
|
123
|
+
if get_wfn:
|
124
|
+
alpha_strs = fci.cistring.make_strings(range(norb), nelec // 2)
|
125
|
+
beta_strs = alpha_strs.copy()
|
126
|
+
wfn_dim = 2 ** (2 * norb)
|
127
|
+
wfn = numpy.zeros(wfn_dim)
|
128
|
+
for i, alpha_str in enumerate(alpha_strs):
|
129
|
+
for j, beta_str in enumerate(beta_strs):
|
130
|
+
merged_str, phase = _merge_alpha_beta_strs(alpha_str, beta_str, norb)
|
131
|
+
wfn[merged_str] = phase * fcivec[i, j]
|
132
|
+
return e + c, QubitWaveFunction.from_array(wfn)
|
133
|
+
|
91
134
|
return e + c
|
92
135
|
|
93
136
|
def compute_energy(self, method: str, *args, **kwargs) -> float:
|
@@ -117,7 +160,7 @@ class QuantumChemistryPySCF(QuantumChemistryBase):
|
|
117
160
|
|
118
161
|
mo_coeff = numpy.eye(norb)
|
119
162
|
mo_occ = numpy.zeros(norb)
|
120
|
-
mo_occ[:nelec // 2] = 2
|
163
|
+
mo_occ[: nelec // 2] = 2
|
121
164
|
|
122
165
|
pyscf_mol = pyscf.gto.M(verbose=0, parse_arg=False)
|
123
166
|
pyscf_mol.nelectron = nelec
|
@@ -139,6 +182,7 @@ class QuantumChemistryPySCF(QuantumChemistryBase):
|
|
139
182
|
|
140
183
|
def _run_ccsd(self, hf=None, **kwargs):
|
141
184
|
from pyscf import cc
|
185
|
+
|
142
186
|
if hf is None:
|
143
187
|
hf = self._get_hf()
|
144
188
|
ccsd = cc.RCCSD(hf)
|
@@ -153,6 +197,7 @@ class QuantumChemistryPySCF(QuantumChemistryBase):
|
|
153
197
|
|
154
198
|
def _run_cisd(self, hf=None, **kwargs):
|
155
199
|
from pyscf import ci
|
200
|
+
|
156
201
|
if hf is None:
|
157
202
|
hf = self._get_hf(**kwargs)
|
158
203
|
cisd = ci.RCISD(hf)
|
@@ -161,6 +206,7 @@ class QuantumChemistryPySCF(QuantumChemistryBase):
|
|
161
206
|
|
162
207
|
def _run_mp2(self, hf=None, **kwargs):
|
163
208
|
from pyscf import mp
|
209
|
+
|
164
210
|
if hf is None:
|
165
211
|
hf = self._get_hf(**kwargs)
|
166
212
|
mp2 = mp.MP2(hf)
|
@@ -171,11 +217,12 @@ class QuantumChemistryPySCF(QuantumChemistryBase):
|
|
171
217
|
base = super().__str__()
|
172
218
|
try:
|
173
219
|
if hasattr(self, "pyscf_molecule"):
|
174
|
-
base += "{:15} : {} ({})\n".format(
|
175
|
-
|
220
|
+
base += "{:15} : {} ({})\n".format(
|
221
|
+
"point_group", self.pyscf_molecule.groupname, self.pyscf_molecule.topgroup
|
222
|
+
)
|
176
223
|
if hasattr(self, "irreps"):
|
177
224
|
base += "{:15} : {}\n".format("irreps", self.irreps)
|
178
|
-
except:
|
225
|
+
except Exception:
|
179
226
|
return base
|
180
227
|
return base
|
181
228
|
|