Skip to content

Commit

Permalink
Merge branch 'PJ-devel' of https://github.com/Praveen91299/tequila in…
Browse files Browse the repository at this point in the history
…to PJ-devel
  • Loading branch information
Praveen Jayakumar committed Jun 29, 2024
2 parents abcd3d2 + d3a232e commit 0e8ac83
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 484 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci_pyquil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ jobs:
python -m pip install --upgrade pip
pip install --upgrade pytest
pip install -r requirements.txt
pip install "pyquil<3.0"
pip install "pyquil<3.0" # needs updates
pip install -e .
pip install --upgrade pip 'urllib3<2' # issues with old pyquil version otherwise
docker pull rigetti/qvm:edge
docker pull rigetti/quilc
docker run --rm -itd -p 5555:5555 rigetti/quilc -R
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Tequila can execute the underlying quantum expectation values on state of the ar

# Installation
Recommended Python version is 3.8-3.9.
Tequila supports linux, osx and windows. However, not all optional dependencies are supported on windows.
Tequila supports linux, osx and windows. However, not all optional dependencies are supported on windows.

## Install from PyPi
**Do not** install like this: (Minecraft lovers excluded)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ qulacs # default simulator (best integration), remove if the installation gives
#qibo <= 0.1.1 # can not be installed in the same environment as gpyopt

#optional optimizers
#phoenics # version on PyPi isc urrently broken, we recommend to install from source (AAG github)
#gpyopt # not in combination with qibo as quantum backend

#optional third party libraries
Expand Down
6 changes: 5 additions & 1 deletion src/tequila/apps/adapt/adapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AdaptParameters:
degeneracy_threshold: float = 5.e-4
silent: bool = False

def __post__init__(self):
def __post_init__(self):
# avoid stacking of same operator-types in a row
if "method_options" in self.optimizer_args:
if "gtol" in self.optimizer_args["method_options"]:
Expand Down Expand Up @@ -150,6 +150,10 @@ def __call__(self, static_variables = None, mp_pool=None, label=None, variables=
variables = {**variables, **static_variables}

U = QCircuit()
if "U" in kwargs:
U = kwargs["U"]
elif hasattr(self.operator_pool, "initialize_circuit"):
U = self.operator_pool.initialize_circuit()

initial_objective = self.make_objective(U, variables = variables)
for k in initial_objective.extract_variables():
Expand Down
11 changes: 8 additions & 3 deletions src/tequila/circuit/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,14 @@ def map_qubits(self, qubit_map: dict):
def compile(self, exponential_pauli=False, *args, **kwargs):
# optimized compiling for single and double qubit excitaitons following arxiv:2005.14475
# Alternative representation in arxiv:2104.05695 (not implemented -> could be added and controlled with optional compile keywords)
if self.is_controlled():
control = list(self.control)
else:
control = []
if self.compile_options == "optimize" and len(self.target) == 2 and exponential_pauli:
p,q = self.target
U0 = X(target=p, control=q)
U1 = Ry(angle=self.parameter, target=q, control=p)
U1 = Ry(angle=self.parameter, target=q, control=[p]+control)
return U0 + U1 + U0
elif self.compile_options == "optimize" and len(self.target) == 4 and exponential_pauli:
p,r,q,s = self.target
Expand All @@ -1093,10 +1097,11 @@ def compile(self, exponential_pauli=False, *args, **kwargs):
U0 += X(target=r, control=p)
U0 += X(target=q)
U0 += X(target=s)
U1 = Ry(angle=-self.parameter, target=p, control=[q,r,s])
U1 = Ry(angle=-self.parameter, target=p, control=[q,r,s]+control)
return U0 + U1 + U0.dagger()
else:
return Trotterized(angle=self.parameter, generator=self.generator, steps=1)
return Trotterized(angle=self.parameter, generator=self.generator, steps=1, control=self.control)


def _convert_Paulistring(paulistring: typing.Union[PauliString, str, dict]) -> PauliString:
'''
Expand Down
15 changes: 1 addition & 14 deletions src/tequila/optimizers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class _Optimizers:
methods: list = None


SUPPORTED_OPTIMIZERS = ['scipy', 'phoenics', 'gpyopt', 'gd']
SUPPORTED_OPTIMIZERS = ['scipy', 'gpyopt', 'gd']
INSTALLED_OPTIMIZERS = {}
INSTALLED_OPTIMIZERS['scipy'] = _Optimizers(cls=OptimizerSciPy,
minimize=minimize_scipy,
Expand All @@ -37,19 +37,6 @@ class _Optimizers:
except ImportError:
has_gpyopt = False

has_phoenics = False
try:
from tequila.optimizers.optimizer_phoenics import OptimizerPhoenics
from tequila.optimizers.optimizer_phoenics import minimize as minimize_phoenics

INSTALLED_OPTIMIZERS['phoenics'] = _Optimizers(cls=OptimizerPhoenics,
minimize=minimize_phoenics,
methods=OptimizerPhoenics.available_methods())
has_phoenics = True
except ImportError:
has_phoenics = False


def show_available_optimizers(module=None):
"""
Returns
Expand Down
3 changes: 2 additions & 1 deletion src/tequila/optimizers/optimizer_gd.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,12 @@ def __call__(self, objective: Objective,


if not self.silent:
self.__dx = numpy.asarray(self.__dx)
print("%3i %+15.8f %+7.2e %7.3e %7.3e %s"
% (step,
e,
e-last,
numpy.max(abs(self.__dx)),
numpy.max([abs(x) for x in self.__dx]),
numpy.sqrt(numpy.average(self.__dx**2)),
comment))

Expand Down
2 changes: 0 additions & 2 deletions src/tequila/optimizers/optimizer_gpyopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import numbers
from tequila.objective.objective import Variable
import warnings

warnings.simplefilter("ignore")
import GPyOpt
from GPyOpt.methods import BayesianOptimization
import numpy as np
Expand Down
Loading

0 comments on commit 0e8ac83

Please sign in to comment.