Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging Devel #146

Merged
merged 11 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci_chemistry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -e .
python -m pip install pyscf
cd tests
ls
pytest test_chemistry.py
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ Currently you need to compile from a separate [fork](https://github.com/kottmanj
See the github page of this fork for installation instruction.
Here is a small [tutorial](https://github.com/aspuru-guzik-group/tequila-tutorials/blob/main/ChemistryMadnessInterface.ipynb) that illustrates the usage.


# Install from source

**Do not** install like this: (Minecraft lovers excluded)
<strike>`pip install tequila`</strike>

Expand Down Expand Up @@ -141,14 +139,14 @@ A Feasible Approach for Automatically Differentiable Unitary Coupled-Cluster on
Chemical Science, 2021, [doi.org/10.1039/D0SC06627C](https://doi.org/10.1039/D0SC06627C).
[arxiv.org/abs/2011.05938](https://arxiv.org/abs/2011.05938)
General techniques are implemented in the chemistry modules of tequila.
See the [tutorials](https://github.com/aspuru-guzik-group/tequila/tree/master/tutorials) for examples.
See the [tutorials](https://github.com/aspuru-guzik-group/tequila-tutorials) for examples.

J.S. Kottmann, P. Schleich, T. Tamayo-Mendoza, A. Aspuru-Guzik.
Reducing Qubit Requirements while Maintaining Numerical Precision for the Variational Quantum Eigensolver: A Basis-Set-Free Approach.
J.Phys.Chem.Lett., 2021, [doi.org/10.1021/acs.jpclett.0c03410](https://doi.org/10.1021/acs.jpclett.0c03410).
[arxiv.org/abs/2008.02819](https://arxiv.org/abs/2008.02819)
[example code](https://github.com/aspuru-guzik-group/tequila/blob/master/tutorials/ChemistryBasisSetFreeVQE.ipynb)
[tutorial on the madness interface](https://github.com/aspuru-guzik-group/tequila/blob/master/tutorials/ChemistryMadnessInterface.ipynb)
[example code](https://github.com/aspuru-guzik-group/tequila-tutorials/blob/main/ChemistryBasisSetFreeVQE.ipynb)
[tutorial on the madness interface](https://github.com/aspuru-guzik-group/tequila-tutorials/blob/main/ChemistryMadnessInterface.ipynb)

A. Cervera-Lierta, J.S. Kottmann, A. Aspuru-Guzik.
The Meta-Variational Quantum Eigensolver.
Expand All @@ -167,10 +165,10 @@ Natural Evolutionary Strategies for Variational Quantum Computation.
J. S. Kottmann, A. Aspuru-Guzik,
Optimized Low-Depth Quantum Circuits for Molecular Electronic Structure using a Separable Pair Approximation,
[arxiv.org/abs/2105.03836](https://arxiv.org/abs/2105.03836)
example code coming soon
implementation currently only on [devel](https://github.com/aspuru-guzik-group/tequila/tree/devel) branch.
[example code](https://github.com/aspuru-guzik-group/tequila-tutorials/blob/main/ChemistrySeparablePairAnsatz.ipynb)
currently needs the [devel](https://github.com/aspuru-guzik-group/tequila/tree/devel) branch of tequila

Let us know, if you want your research project to be included in this list!
Let us know, if you want your research project and/or tutorial to be included in this list!

# Dependencies
Support for additional optimizers or quantum backends can be activated by intalling them in your environment.
Expand Down
59 changes: 42 additions & 17 deletions src/tequila/apps/adapt/adapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy
import dataclasses
import warnings
from itertools import combinations


@dataclasses.dataclass
Expand Down Expand Up @@ -139,7 +140,7 @@ def __call__(self, static_variables = None, mp_pool=None, label=None, variables=
warnings.warn("variable {} of initial objective not given, setting to 0.0 and activate optimization".format(k), TequilaWarning)
variables[k] = 0.0

energy = 0.0
energy = simulate(initial_objective, variables=variables)
for iter in range(self.parameters.maxiter):
current_label = (iter,0)
if label is not None:
Expand All @@ -155,7 +156,7 @@ def __call__(self, static_variables = None, mp_pool=None, label=None, variables=
print("pool gradient norm is {:+2.8f}, convergence criterion met".format(grad_norm))
break
if numpy.abs(max_grad) < self.parameters.max_gradient_convergence:
print("max pool gradient is {:+2.8f}, convergence criterion met".format(grad_norm))
print("max pool gradient is {:+2.8f}, convergence criterion |max(grad)|<{} met".format(max_grad, self.parameters.max_gradient_convergence))
break

batch_size = self.parameters.batch_size
Expand Down Expand Up @@ -291,19 +292,18 @@ def __init__(self, molecule, indices:str):
self.molecule = molecule

if isinstance(indices, str):
if indices.upper() == "UPCCGSD":
indices = self.make_indices_doubles(generalized=True)
indices += self.make_indices_singles(generalized=True)
elif indices.upper() == "UPCCSD":
indices = self.make_indices_doubles(generalized=False)
indices += self.make_indices_singles(generalized=False)
elif indices.upper() == "UPCCD":
indices = self.make_indices_doubles(generalized=False)
elif indices.upper() == "UPCCGD":
indices = self.make_indices_doubles(generalized=True)
else:
if not "CC" in indices.upper():
raise TequilaException("Pool of type {} not yet supported.\nCreate your own by passing the initialized indices".format(indices))

generalized = True if "G" in indices.upper() else False
paired = True if "P" in indices.upper() else False
singles = True if "S" in indices.upper() else False
doubles = True if "D" in indices.upper() else False

indices = []
if doubles: indices += self.make_indices_doubles(generalized=generalized, paired=paired)
if singles: indices += self.make_indices_singles(generalized=generalized)

indices = [tuple(k) for k in indices]
super().__init__(generators=indices)

Expand All @@ -323,11 +323,9 @@ def make_indices_singles(self, generalized=False):
continue
indices.append([(2*p, 2*q)])
indices.append([(2*p+1, 2*q+1)])
return indices
return self.sort_and_filter_unique_indices(indices)

def make_indices_doubles(self, generalized=False, paired=True):
# only paired doubles supported currently
assert paired
indices = []
for p in range(self.molecule.n_electrons//2):
for q in range(self.molecule.n_electrons//2, self.molecule.n_orbitals):
Expand All @@ -343,7 +341,33 @@ def make_indices_doubles(self, generalized=False, paired=True):
continue
indices.append(idx)

return indices
if not paired:
indices += self.make_indices_doubles_all(generalized=generalized)

return self.sort_and_filter_unique_indices(indices)

def make_indices_doubles_all(self, generalized=False):
singles = self.make_indices_singles(generalized=generalized)
unwrapped = [x[0] for x in singles]
# now make all combinations of singles
indices = [x for x in combinations(unwrapped, 2)]
return self.sort_and_filter_unique_indices(indices)

def sort_and_filter_unique_indices(self, indices):
# sort as: [[(a,b),(c,d),(e,f)...],...]with a<c, a<b, c<d
sorted_indices = []
for idx in indices:
idx = tuple([tuple(sorted(pair)) for pair in idx]) # sort internal pairs (a<b, c<d, etc)
# avoid having orbitals show up multiple times in excitatin strings
idx = tuple([pair for pair in idx if sum([1 for pair2 in idx if pair[0] in pair2 or pair[1] in pair2 ])==1 ])
if len(idx) == 0:
continue
idx = tuple(list(set(idx))) # avoid repetitions (like ((0,2),(0,2)))
idx = tuple(sorted(idx, key=lambda x:x[0])) # sort pairs by first entry (a<c)
sorted_indices.append(idx)
return list(set(sorted_indices))



def make_unitary(self, k, label):
return self.molecule.make_excitation_gate(indices=self.generators[k], angle=(self.generators[k], label), assume_real=True)
Expand Down Expand Up @@ -386,3 +410,4 @@ def __call__(self, U, *args, **kwargs):
S2 = ExpectationValue(H=Qp, U=circuit+Ux.dagger())
objective += numpy.abs(self.factors[i])*S2
return objective

Loading