Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4768357
Update version.py
kottmanj Oct 7, 2025
6848e6b
Update README.md (#424)
kottmanj Jul 31, 2025
309d127
Adding excitationsolve optimizer
S-Erik Oct 26, 2025
0753cab
Fixing return value type hint in __call__
S-Erik Oct 26, 2025
405922b
Adding pip install excitationsolve to ci_basic. Put ExcSolve behind t…
S-Erik Nov 2, 2025
23f2ad8
Update Python versions in CI workflow
kottmanj Nov 11, 2025
85f0944
Update ci_basic_autograd.yml
kottmanj Nov 11, 2025
7fcf35e
Update Python version in CI workflow to 3.11
kottmanj Nov 11, 2025
a78533d
Update Python version in CI workflow to 3.11
kottmanj Nov 11, 2025
5d4527f
Update ci_conda_madness.yml
kottmanj Nov 11, 2025
556570f
Update ci_ml.yml
kottmanj Nov 11, 2025
381bf42
Update Python version in CI workflow to 3.11
kottmanj Nov 11, 2025
baf343a
Revise Python version recommendation in README
kottmanj Nov 11, 2025
045b8ae
Change Python version from 3.11 to 3.10
kottmanj Nov 11, 2025
8c889b3
Fix Python version format in CI workflow
kottmanj Nov 11, 2025
437b277
Comment out h5py installation in CI workflow
kottmanj Nov 11, 2025
cbc2427
Disable tests for TaperedBinary and REORDEREDTAPEREDBINARY
kottmanj Nov 14, 2025
cfdb2ca
Update test_chemistry.py
kottmanj Nov 14, 2025
582ff48
Refactor transformation parameterization in tests
kottmanj Nov 14, 2025
9154136
Change Python version in CI workflow to 3.9
kottmanj Nov 15, 2025
7cd2546
Refactor parametrize decorators for tests
kottmanj Nov 15, 2025
9004af1
Fix parameterization in test_ucc_psi4
kottmanj Nov 15, 2025
a5b1a6b
Update ci_pyquil.yml
kottmanj Nov 17, 2025
1af2122
Update test_chemistry.py
kottmanj Nov 17, 2025
ea7fa2c
Delete .github/workflows/ci_pyquil.yml
kottmanj Nov 17, 2025
4740567
Change Python version in CI workflow to 3.09 (cuda issue)
kottmanj Nov 17, 2025
a024b8f
Fix Python version in CI workflow
kottmanj Nov 17, 2025
0ae7a18
Update ci_backends.yml
kottmanj Nov 17, 2025
3004c40
Update main_trot.py
kottmanj Nov 17, 2025
cfcc544
Update main_trot.py
kottmanj Nov 18, 2025
652bfba
Add zero norm check for Comm before eigsh call
kottmanj Nov 19, 2025
8875272
Add debug prints for Comm and operator calculations
kottmanj Nov 20, 2025
239f616
Update main_trot.py
kottmanj Nov 20, 2025
be2cfbf
Update main_trot.py
kottmanj Nov 20, 2025
566b274
Update main_trot.py
kottmanj Nov 20, 2025
c20b99d
Merge branch 'devel' into excsolve
kottmanj Jan 4, 2026
0a39300
Merge branch 'devel' into excsolve
kottmanj Jan 19, 2026
b058699
Update main_trot.py
kottmanj Feb 2, 2026
f6792da
Update main_trot.py
kottmanj Feb 2, 2026
2ec1c83
Implement error handling in basis state index calculation
kottmanj Feb 2, 2026
d964af4
Fix exception handling syntax in fermionic_functions.py
kottmanj Feb 2, 2026
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
3 changes: 2 additions & 1 deletion .github/workflows/ci_basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10']
python-version: ['3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand All @@ -30,6 +30,7 @@ jobs:
pip install -r requirements.txt
# test default simulator against in-house simulator
pip install git+https://github.com/Mikel-Ma/spex@devel
pip install excitationsolve
- name: Lint with flake8
run: |
pip install flake8
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_basic_autograd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_chemistry_psi4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
miniconda-version: 'latest'
auto-activate-base: false
python-version: '3.10'
python-version: '3.11'

- name: Initialize Conda for the shell
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_chemistry_pyscf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: ['3.10']

steps:
- uses: actions/checkout@v2
Expand All @@ -39,7 +39,7 @@ jobs:
python -m pip install -r requirements.txt
python -m pip install -e .
python -m pip install pyscf
python -m pip install 'h5py <= 3.1'
#python -m pip install 'h5py <= 3.1'
cd tests
ls
pytest test_chemistry.py test_TrotErr.py -m "not dependencies"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_conda_madness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.11]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_ml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.11]

steps:
- uses: actions/checkout@v2
Expand Down
45 changes: 0 additions & 45 deletions .github/workflows/ci_pyquil.yml

This file was deleted.

12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ Tequila can execute the underlying quantum expectation values on state of the ar
# Getting Started

Get started with our collection of
- *[Tutorials](https://tequilahub.github.io/tequila-tutorials/)*
- *[Tutorials](https://tequilahub.github.io/tequila-tutorials/)*
- *[Documentation](https://tequilahub.github.io/tequila-tutorials/docs/sphinx/)*

Further sources:
- [overview article](https://arxiv.org/abs/2011.03057)
- [tequila in a nutshell](https://kottmanj.github.io/tequila-in-a-nutshell/#/)
- [talks and slides](https://kottmanj.github.io/talks_and_material/)

# Installation
Recommended Python version is 3.10 (3.11).
Recommended Python version is 3.11 (3.10 or 3.12 shouldn't be a problem either).
Tequila supports linux, osx and windows. However, not all optional dependencies (especially chemistry) are supported on windows.

## Install from PyPi
Expand Down Expand Up @@ -295,12 +296,7 @@ pip install pyscf
Works similar as Psi4. Classical methods are also integrated in the madness interface allowing to use them in a basis-set-free representation.

# Documentation
You can build the documentation by navigating to `docs` and entering `make html`.
Open the documentation with a browser over like `firefox docs/build/html/index.html`
Note that you will need some additional python packages like `sphinx` and `mr2` that are not explicitly listed in the requirements.txt

You can also visit our prebuild online [documentation](https://tequilahub.github.io/tequila/)
that will correspond to the github master branch
see [here](https://tequilahub.github.io/tequila-tutorials/docs/sphinx/)

# How to contribute
If you find any bugs or inconveniences in `tequila` please don't be shy and let us know.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pytest
openfermion ~= 1.0 # can not be smaller than 1.0
#cmake # needed by qulacs, can be removed otherwise, now in qulacs requirements
qulacs # default simulator (best integration), remove if the installation gives you trouble and just install one of the other supported backend. Version restriction only for noise models, otherwise the new version is fine
excitationsolve

#optional quantum backends
#cirq >= 0.9.2 #
Expand Down
8 changes: 6 additions & 2 deletions src/tequila/grouping/fermionic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,12 @@ def find_index(basis_state):
index = 0
n_qubits = len(basis_state)
for j in range(n_qubits):
index += int(basis_state[j]) * 2 ** (n_qubits - j - 1)

try:
index += int(basis_state[j]) * 2 ** (n_qubits - j - 1)
except Exception as E:
print("basis_state=", basis_state)
print(f"j={j}")
print(f"basis_state[j]={basis_state[j]}")
return index


Expand Down
19 changes: 17 additions & 2 deletions src/tequila/optimizers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from tequila.optimizers.optimizer_base import OptimizerHistory, Optimizer, TequilaOptimizerException, OptimizerResults
from tequila.optimizers.optimizer_scipy import OptimizerSciPy
from tequila.optimizers.optimizer_gd import OptimizerGD
from tequila.optimizers.optimizer_excsolve import OptimizerExcitationSolve
from tequila.optimizers.optimizer_scipy import minimize as minimize_scipy
from tequila.optimizers.optimizer_gd import minimize as minimize_gd
from tequila.optimizers.optimizer_excsolve import minimize as minimize_excsolve
from tequila.simulators.simulator_api import simulate
from dataclasses import dataclass

Expand All @@ -18,13 +20,14 @@ class _Optimizers:
methods: list = None


SUPPORTED_OPTIMIZERS = ["scipy", "gpyopt", "gd"]
SUPPORTED_OPTIMIZERS = ["scipy", "gpyopt", "gd", "excitationsolve"]
INSTALLED_OPTIMIZERS = {}
INSTALLED_OPTIMIZERS["scipy"] = _Optimizers(
cls=OptimizerSciPy, minimize=minimize_scipy, methods=OptimizerSciPy.available_methods()
)
INSTALLED_OPTIMIZERS["gd"] = _Optimizers(cls=OptimizerGD, minimize=minimize_gd, methods=OptimizerGD.available_methods())


has_gpyopt = False
try:
from tequila.optimizers.optimizer_gpyopt import OptimizerGPyOpt
Expand All @@ -37,6 +40,18 @@ class _Optimizers:
except ImportError:
has_gpyopt = False

has_excsolve = False
try:
from tequila.optimizers.optimizer_excsolve import OptimizerExcitationSolve
from tequila.optimizers.optimizer_excsolve import minimize as minimize_excsolve

INSTALLED_OPTIMIZERS["excitationsolve"] = _Optimizers(
cls=OptimizerExcitationSolve, minimize=minimize_excsolve, methods=OptimizerExcitationSolve.available_methods()
)
has_excsolve = True
except ImportError:
has_excsolve = False


def show_available_optimizers(module=None):
"""
Expand Down Expand Up @@ -138,5 +153,5 @@ def minimize(
)

raise TequilaOptimizerException(
"Could not find optimization method {} in tequila optimizers. You might miss dependencies"
f"Could not find optimization method {method} in tequila optimizers. You might miss dependencies"
)
142 changes: 142 additions & 0 deletions src/tequila/optimizers/optimizer_excsolve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import scipy
import numpy
import typing
import numbers
from excitationsolve import ExcitationSolveScipy
from tequila.objective import Objective
from tequila.objective.objective import assign_variable, Variable, format_variable_dictionary, format_variable_list
from .optimizer_base import Optimizer, OptimizerResults
from ._containers import _EvalContainer, _GradContainer, _HessContainer, _QngContainer
from .optimizer_scipy import SciPyResults
from tequila.utils.exceptions import TequilaException
from tequila.circuit.noise import NoiseModel
from tequila.tools.qng import get_qng_combos

from dataclasses import dataclass


class OptimizerExcitationSolve(Optimizer):
r"""The ExcitationSolve optimizer as a SciPy optimizer that can be given to the scipy.optimize.minimize function.

Usage:
```python
excsolve_obj = ExcitationSolveScipy(maxiter=100, tol=1e-10, save_parameters=True)
optimizer = excsolve_obj.minimize
res = scipy.optimize.minimize(cost, params, method=optimizer)
energies = excsolve_obj.energies
counts = excsolve_obj.nfevs
```

Note that this optimizer never needs to evaluate the ansatz circuit
at the (current) optimal parameters, unless the optimal parameters fall onto
the sample points used to reconstruct the energy function.
Therefore, when used with a qiskit VQE object, the energies transmitted
to a VQE callback function, do not seem to improve or converge. Nevertheless,
the determined optimal energy and parameters are still returned.

Args:
maxiter (int): Maximum number of VQE iterations (maximum number of times to optimize all parameters)
tol: Threshold of energy difference after subsequent VQE iterations defining convergence
num_samples (int, optional): Number of different parameter values at which to sample
the energy to reconstruct the energy function in one parameter.
Must be greater or equal to 5. Defaults to 5.
hf_energy (float | None, optional): The Hartree-Fock energy, i.e. the energy of the
system where all parameters in the circuit are zero. If none, this will be
calculated by evaluating the energy of the ansatz with all parameters set to zero.
If this energy is known from a prior classical calculation, e.g. a Hartree-Fock
calculation, one energy evaluation is saved. Defaults to None.
save_parameters (bool, optional): If True, params member variable contains
all optimal parameter values after each optimization step,
i.e. after optimizing each single parameter. Defaults to False.
param_scaling (float, optional): Factor used for rescaling the parameters. This ExcitationSolve optimizer
expects the parameters to be 2\pi periodic. For example, in Qiskit
the excitation parameters result in excitation operators being \pi periodic.
Therefore, we use a factor of 0.5 for qiskit, resulting in a Period of 2\pi.
"""

@classmethod
def available_methods(cls):
""":return: All tested available methods"""
return ["excitationsolve"]

def __init__(
self, maxiter, tol=1e-12, num_samples=5, hf_energy=None, save_parameters=False, param_scaling=0.5, **kwargs
):
if maxiter is None:
maxiter = 10

super().__init__(**kwargs)

self.opt = ExcitationSolveScipy(
maxiter=maxiter,
tol=tol,
num_samples=num_samples,
hf_energy=hf_energy,
save_parameters=save_parameters,
param_scaling=param_scaling,
)

def __call__(
self,
objective: Objective,
variables: typing.List[Variable],
initial_values: typing.Dict[Variable, numbers.Real] = None,
*args,
**kwargs,
) -> SciPyResults:
objective = objective.contract()
infostring = "{:15} : {}\n".format("Method", "ExcitationSolve")
infostring += "{:15} : {} expectationvalues\n".format("Objective", objective.count_expectationvalues())

# if self.save_history and reset_history:
# self.reset_history()

active_angles, passive_angles, variables = self.initialize_variables(objective, initial_values, variables)

# Transform the initial value directory into (ordered) arrays
param_keys, param_values = zip(*active_angles.items())
param_values = numpy.array(param_values)

# do the compilation here to avoid costly recompilation during the optimization
compiled_objective = self.compile_objective(objective=objective, *args, **kwargs)
E = _EvalContainer(
objective=compiled_objective,
param_keys=param_keys,
samples=self.samples,
passive_angles=passive_angles,
save_history=self.save_history,
print_level=self.print_level,
)

res = self.opt.minimize(E, param_values, *args, **kwargs)

if self.save_history:
self.history.energies = self.opt.energies
self.history.angles = self.opt.params
# self.history.gradients = self.opt.energies_shiftste

return SciPyResults(energy=res.fun, history=self.history, variables=res.x, scipy_result=res)


def minimize(
objective: Objective,
variables: typing.List[Variable],
initial_values: typing.Dict[Variable, numbers.Real] = None,
method: str = "excitationsolve",
maxiter: int = 10,
*args,
**kwargs,
):
optimize = OptimizerExcitationSolve(
maxiter=maxiter,
save_parameters=True,
*args,
**kwargs,
)
return optimize(
objective=objective,
variables=variables,
initial_values=initial_values,
*args,
**kwargs,
)
2 changes: 1 addition & 1 deletion src/tequila/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.9.10.dev"
__version__ = "1.9.10"
__author__ = "Tequila Developers "
Loading
Loading