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

New release v0.4.1 into main #349

Merged
merged 90 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
3f141ed
Update develop to catch up with main version 0.3.3 (#249)
ValentinS4t1qbit Nov 9, 2022
f45cdf5
Fix link of fig in qchem & excited states notebook (#250)
alexfleury-sb Nov 9, 2022
e58c8b0
allow single flip index dis for qcc (#247)
JamesB-1qbit Nov 15, 2022
196d2d7
Richardson extrapolation: bug fix + error estimation (#252)
KrzysztofB-1qbit Nov 21, 2022
6a5e763
Bugfix: DMET with QCC (#253)
alexfleury-sb Nov 23, 2022
9af6682
iQCC using only Clifford circuits notebook (#254)
JamesB-1qbit Nov 23, 2022
1383c35
pUCCD ansatz (#251)
alexfleury-sb Nov 25, 2022
d207e35
UHF reference (#240)
JamesB-1qbit Nov 28, 2022
f4d46ad
added multi-product, grid_circuits and discrete_clock (#257)
JamesB-1qbit Nov 28, 2022
b7f62ad
translation to pennylane (#260)
JamesB-1qbit Dec 19, 2022
5d3e9da
bump testing version to 3.8 (#262)
JamesB-1qbit Dec 23, 2022
3559208
Auto threshold cutoff for small coefficients in LCU (#261)
JamesB-1qbit Jan 3, 2023
61bfcae
Openshell DMET (#208)
alexfleury-sb Jan 4, 2023
9b9b201
Save mid-circuit measurement (#256)
KrzysztofB-1qbit Jan 5, 2023
18cd0a6
Merge branch 'main' into develop
ValentinS4t1qbit Jan 11, 2023
f403b5a
Fix for IBMQConnection (#264)
ValentinS4t1qbit Jan 12, 2023
260735e
Updated copyright year to 2023 (#267)
JamesB-1qbit Jan 18, 2023
3cc81c8
added draw method to circuit (#266)
JamesB-1qbit Jan 25, 2023
036f152
Cirq, qulacs, pennylane and projectq operator translation functions (…
alexfleury-sb Jan 25, 2023
9e8b0f3
Fixed identity operator evaluation and extended the accepted input ty…
alexfleury-sb Jan 27, 2023
e0bbb52
Temporarily disabling OS-DMET (#271)
alexfleury-sb Feb 3, 2023
cfff6eb
Link to new example repo
ValentinS4t1qbit Feb 6, 2023
eceade1
Update README.rst
ValentinS4t1qbit Feb 6, 2023
bbeb795
Merge branch 'main' into develop
ValentinS4t1qbit Feb 6, 2023
5177bbc
Revert changes that broke tests (#275)
JamesB-1qbit Feb 9, 2023
f952bdf
DMET + frozen orbitals for each fragment (#276)
alexfleury-sb Feb 13, 2023
4c70238
Example folder relocated to new repo Tangelo-Examples (#274)
JamesB-1qbit Feb 13, 2023
7f26236
Docs update (#272)
alexfleury-sb Feb 13, 2023
0809250
Desired measurement result (#263)
KrzysztofB-1qbit Feb 15, 2023
d9f788b
fix error for imaginary qubit_op with desired meas result (#278)
JamesB-1qbit Feb 17, 2023
535d38d
Merge branch 'main' into develop
ValentinS4t1qbit Feb 17, 2023
a8b59ed
Integrate bug fix into main before release (#278) (#279) (#280)
ValentinS4t1qbit Feb 18, 2023
92444b8
Depth function performance increase (#285)
ValentinS4t1qbit Feb 27, 2023
aedf836
Fix for (inverse of S and T gate) #287. (#288)
alexfleury-sb Mar 8, 2023
e1933bf
Translation perf tests (operator, circuit) (#289)
ValentinS4t1qbit Mar 9, 2023
7685b7e
deterministic desired_meas_result (#290)
JamesB-1qbit Mar 16, 2023
e290172
Mifnohelper print: remove problem handle (#293)
ValentinS4t1qbit Mar 17, 2023
e9e4842
Combinatorial mapping of fermionic Hamiltonians (#286)
alexfleury-sb Mar 23, 2023
748d861
Re-enabling open-shell DMET (#291)
alexfleury-sb Mar 31, 2023
e57563f
Support for symbolic simulator (simpy) (#292)
alexfleury-sb Apr 4, 2023
99a1b68
Arg simulate_options and projective_circuit to VQESolver (#298)
JamesB-1qbit May 8, 2023
1d7cae8
Supporting symbols as parameters and add nsimplify to results (#300)
alexfleury-sb May 9, 2023
9110900
Trim trivial qubits from circuit and Hamiltonian (#302)
elloyd-1qbit May 17, 2023
0732b9c
Push contributors towards develop and not to main for PRs (#303)
ValentinS4t1qbit May 18, 2023
e72f2e9
Set the DMET virtual orbital truncation threshold at the user level (…
alexfleury-sb May 23, 2023
c75e261
Trim bug (#305)
JamesB-1qbit May 24, 2023
7b704d9
Added typing for option dictionaries in quantum agorithms (#307)
JamesB-1qbit Jun 5, 2023
217a2a9
IntegralSolver class: base + support for Psi4 (#297)
JamesB-1qbit Jun 5, 2023
a6e73ed
Change multi-controlled CNOT to multi-controlled CX (#308)
JamesB-1qbit Jun 6, 2023
0e3d8a2
Braket connection (#312)
ValentinS4t1qbit Jun 15, 2023
c2b6dab
Support for UMP2 initial parameters (#310)
alexfleury-sb Jun 15, 2023
c6b185d
Checkfile for IntegralSolverPySCF (#311)
alexfleury-sb Jun 15, 2023
c095391
QubitOperator import from Tangelo, for better encapsulation (#299)
ValentinS4t1qbit Jun 16, 2023
501a582
FCISolverPsi4 (#309)
JamesB-1qbit Jun 18, 2023
160e57e
Removed deprecated Linq functions (#316)
ValentinS4t1qbit Jun 19, 2023
960f563
CCSD solver psi4 (#313)
JamesB-1qbit Jun 20, 2023
716efc1
ADAPT: add spin to available options (#317)
JamesB-1qbit Jun 21, 2023
58e9031
MP2 psi4 (#315)
JamesB-1qbit Jun 21, 2023
7a43afb
skip performance tests (Linq) in pytest (#319)
JamesB-1qbit Jun 22, 2023
1b0859d
Typos in docs (#321)
alexfleury-sb Jun 22, 2023
3f403fb
DMET Effective Core Potential fix(related to #306) (#318)
JamesB-1qbit Jun 22, 2023
922d531
Change installation (#320)
JamesB-1qbit Jun 23, 2023
226b1fa
DMET-ecp test fix: change optimizer to minimize square (#323)
JamesB-1qbit Jun 27, 2023
334abe9
improved Error message for MP2 initialization in UCCSD (pySCf current…
JamesB-1qbit Jun 27, 2023
476b9b9
Qiskit-related: deprecation update to SparsePauliOp and bug workaroun…
JamesB-1qbit Jun 29, 2023
908a10f
Stim clifford simulator integration (#314)
elloyd-1qbit Jun 29, 2023
2124f6f
Bump develop to v0.4.0.RC (#327)
ValentinS4t1qbit Jun 29, 2023
11874b7
Update _version.py
ValentinS4t1qbit Jul 5, 2023
29a6b40
Fixed requirements (#324)
ccoulombe Jul 11, 2023
eefaf8e
Fix combinatorial mapping when spin!=0. (#330)
alexfleury-sb Jul 17, 2023
275e175
QPESolver implementation (#332)
JamesB-1qbit Aug 11, 2023
7f77f43
Fixes to MIFNOHelper after QEMIST Cloud 0.6.0 release (#331)
alexfleury-sb Aug 14, 2023
5a20e9a
Adding more python versions to tests (#333)
ValentinS4t1qbit Aug 21, 2023
d91305c
Bug Fix: n_shots parameter was ignored in get_expectation_value (#337)
JamesB-1qbit Sep 12, 2023
b1c3caa
convert all gate names to upper case and check that it is a string (#…
JamesB-1qbit Sep 14, 2023
a997b0c
Fixes for new version of qiskit runtime. Tangelo now supports sampler…
ValentinS4t1qbit Sep 17, 2023
0290bd9
Function that returns the qubits used for Truncated Taylor Series (#339)
JamesB-1qbit Sep 19, 2023
8fbf744
Support for following VQE minimization in VQESolver (#342)
alexfleury-sb Sep 19, 2023
d249ac0
Readme update: more straight to the point. (#343)
ValentinS4t1qbit Sep 20, 2023
79a0b18
Merge branch 'main' into develop
ValentinS4t1qbit Sep 20, 2023
202517a
Classical solver uses mo_coeff from SecondQuantizedMolecule (#338)
JamesB-1qbit Sep 21, 2023
4892a3d
Simplify method for circuits (#345)
ValentinS4t1qbit Oct 1, 2023
af4387f
QM/MM support with electrostatic embedding (#336)
JamesB-1qbit Oct 12, 2023
f29aa3e
Small fixes for ILC (#346)
JamesB-1qbit Oct 12, 2023
63e617a
Update README.rst
ValentinS4t1qbit Oct 16, 2023
841e500
QM/MM: charges solvers made consistent with users choices. (#347)
alexfleury-sb Oct 16, 2023
e151e46
Performance upgrade to combinatorial mapping (#348)
ValentinS4t1qbit Oct 17, 2023
a9dc04c
Bumping Tangelo version number in _version.py
web-flow Oct 18, 2023
ac079d9
Update CHANGELOG.md
ValentinS4t1qbit Oct 18, 2023
bae916c
Merge branch 'main' into release/v0.4.1
ValentinS4t1qbit Oct 18, 2023
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
8 changes: 7 additions & 1 deletion .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install pip, wheel, pytest, jupyter
- name: Install pip, wheel, pytest, jupyter, pyqsp
run: |
python -m pip install --upgrade pip
pip install wheel
Expand Down Expand Up @@ -77,6 +77,12 @@ jobs:
python -m pip install git+https://github.com/pyscf/semiempirical
if: always()

- name: Install rdkit, openbabel-wheel
run: |
python -m pip install rdkit
python -m pip install openbabel-wheel
if: always()

- name: tangelo tests
run: |
cd tangelo
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/run_psi4_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ jobs:
conda init
if: always()

- name: Install pip, wheel, pytest, jupyter
- name: Install pip, wheel, pytest, jupyter, openbabel, rdkit, openmm
run: |
python -m pip install --upgrade pip
pip install wheel
pip install pytest
pip install pytest-cov
pip install rdkit
pip install openbabel-wheel
conda install -c conda-forge openmm

- name: Install qulacs
run: |
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,32 @@
This file documents the main changes between versions of the code.


## [0.4.1] - 2023-10-18

### Added

- QM/MM problem decomposition
- QPE framework
- Truncated taylor series function returning qubits
- simplify method on Circuit

### Changed

- Automated testing currently covering python 3.8, 3.9, 3.10, 3.11 (#333)
- Installation: pyscf removed from requirements
- Performance improvement: combinatorial mapping
- Feature: ILC iteration now implements exact expansion / parameters
- Feature: VQE-like algorithms verbose mode now prints and tracks energies, for users interested in the convergence of the algorithm.
- Bugfix: Combinatorial mapping now handles spin != 0 (#330)
- Bugfix: get_expectation_value takes into account n_shots for all backends supporting the option.
- Bugfix: Fix corner case of FCI and CCSD solvers calculations (mo coefficients were occasionally recomputed differently).
- Bugfix: Updates in IBMConnection to keep up with changes in qiskit-runtime.


### Deprecatedv / Removed



## [0.4.0] - 2023-06-29

### Added
Expand Down
17 changes: 14 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,19 @@ The contribution process is detailed in the `contributions <./CONTRIBUTIONS.rst>
Citations
---------

If you use Tangelo in your research, please cite:

Valentin Senicourt, James Brown, Alexandre Fleury, Ryan Day, Erika Lloyd, Marc P. Coons, Krzysztof Bieniasz, Lee Huntington, Alejandro J. Garza, Shunji Matsuura, Rudi Plesch, Takeshi Yamazaki, and Arman Zaribafiyan Tangelo: An Open-source Python Package for End-to-end Chemistry Workflows on Quantum Computers 2022 arXiv:2206.12424
If you use Tangelo in your research, please cite the `Tangelo release paper <https://arxiv.org/abs/2206.12424>`_ and consider mentioning Tangelo in your talks.

.. code-block:: latex

@article{tangelo,
author = {Valentin Senicourt and James Brown and Alexandre Fleury and Ryan Day and Erika Lloyd and Marc P. Coons and Krzysztof Bieniasz and Lee Huntington and Alejandro J. Garza and Shunji Matsuura and Rudi Plesch and Takeshi Yamazaki and Arman Zaribafiyan},
title = {Tangelo: An Open-source Python Package for End-to-end Chemistry Workflows on Quantum Computers},
year = {2022},
url= {https://arxiv.org/abs/2206.12424},
number = {arXiv:2206.12424},
eprint = {arXiv:2206.12424},
publisher = {{arXiv}},
doi = {10.48550/arXiv.2206.12424}
}

© Good Chemistry Company 2023. This software is released under the Apache Software License version 2.0.
2 changes: 1 addition & 1 deletion tangelo/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

""" Define version number here. It is read in setup.py, and bumped automatically
when using the new release Github action. """
__version__ = "0.4.0"
__version__ = "0.4.1"
24 changes: 18 additions & 6 deletions tangelo/algorithms/classical/ccsd_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sympy.combinatorics.permutations import Permutation

from tangelo.toolboxes.molecular_computation.molecule import SecondQuantizedMolecule
from tangelo.toolboxes.molecular_computation import IntegralSolverPsi4, IntegralSolverPySCF
from tangelo.toolboxes.molecular_computation import IntegralSolverPsi4, IntegralSolverPySCF, IntegralSolverPsi4QMMM
from tangelo.algorithms.electronic_structure_solver import ElectronicStructureSolver
from tangelo.helpers.utils import installed_chem_backends, is_package_installed

Expand Down Expand Up @@ -161,16 +161,20 @@ def __init__(self, molecule: SecondQuantizedMolecule):
f"with a UHF reference in {self.__class__.__name__}")

# Frozen orbitals must be declared before calling compute_mean_field to be saved in ref_wfn for Psi4 ccsd.
intsolve = IntegralSolverPsi4()
intsolve = IntegralSolverPsi4() if not hasattr(molecule.solver, "charges") else IntegralSolverPsi4QMMM(molecule.solver.combinedcharges)
self.backend.set_options({'basis': molecule.basis, 'frozen_docc': [self.n_frozen_occ], 'frozen_uocc': [self.n_frozen_vir],
'reference': self.ref})

self.molecule = SecondQuantizedMolecule(xyz=molecule.xyz, q=molecule.q, spin=molecule.spin,
solver=intsolve,
basis=molecule.basis,
ecp=molecule.ecp,
symmetry=False,
uhf=molecule.uhf,
frozen_orbitals=molecule.frozen_orbitals)

self.init_mo_coeff = molecule.mo_coeff
self.extra_nuc_energy = 0. if not hasattr(molecule.solver, "charges") else self.molecule.solver.ext_pot.computeNuclearEnergy(self.molecule.solver.mol)
self.basis = molecule.basis

def simulate(self):
Expand All @@ -185,13 +189,15 @@ def simulate(self):
if self.n_frozen_occ or self.n_frozen_vir:
if not self.molecule.uhf:
mo_order = self.molecule.frozen_occupied + self.molecule.active_occupied + self.molecule.active_virtual + self.molecule.frozen_virtual
self.molecule.solver.modify_c(wfn, self.init_mo_coeff)
# Obtain swap operations that will take the unordered list back to ordered with the correct active space in the middle.
swap_ops = Permutation(mo_order).transpositions()
for swap_op in swap_ops:
wfn.Ca().rotate_columns(0, swap_op[0], swap_op[1], np.deg2rad(90))

else:

# Modify Ca mo_coeff in reference wavefunction to initial mo_coeff
self.molecule.solver.modify_c(wfn, self.init_mo_coeff[0])
# Obtain swap operations that will take the unordered list back to ordered with the correct active space in the middle.
mo_order = (self.molecule.frozen_occupied[0] + self.molecule.active_occupied[0]
+ self.molecule.active_virtual[0] + self.molecule.frozen_virtual[0])
Expand All @@ -200,6 +206,7 @@ def simulate(self):
wfn.Ca().rotate_columns(0, swap_op[0], swap_op[1], np.deg2rad(90))

# Repeat for Beta orbitals
self.molecule.solver.modify_c(wfn, self.init_mo_coeff[1], False)
mo_order_b = (self.molecule.frozen_occupied[1] + self.molecule.active_occupied[1]
+ self.molecule.active_virtual[1] + self.molecule.frozen_virtual[1])
swap_ops = Permutation(mo_order_b).transpositions()
Expand All @@ -208,9 +215,14 @@ def simulate(self):

self.backend.set_options({'basis': self.basis, 'frozen_docc': [self.n_frozen_occ], 'frozen_uocc': [self.n_frozen_vir],
'qc_module': 'ccenergy', 'reference': self.ref})
energy, self.ccwfn = self.backend.energy('ccsd', molecule=self.molecule.solver.mol,
basis=self.basis, return_wfn=True, ref_wfn=wfn)
return energy
if hasattr(self.molecule, "charges") and self.backend.__version__ >= "1.6":
energy, self.ccwfn = self.backend.energy('ccsd', molecule=self.molecule.solver.mol,
basis=self.basis, return_wfn=True, ref_wfn=wfn,
external_potentials=self.molecule.solver.external_potentials)
else:
energy, self.ccwfn = self.backend.energy('ccsd', molecule=self.molecule.solver.mol,
basis=self.basis, return_wfn=True, ref_wfn=wfn)
return energy + self.extra_nuc_energy

def get_rdm(self):
"""Compute the Full CI 1- and 2-particle reduced density matrices.
Expand Down
16 changes: 15 additions & 1 deletion tangelo/algorithms/classical/fci_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ def __init__(self, molecule: SecondQuantizedMolecule):
self.backend.core.clean_variables()
self.ciwfn = None
self.degenerate_mo_energies = False
self.extra_nuc_energy = 0
if isinstance(molecule.solver, IntegralSolverPsi4) and not molecule.symmetry:
self.molecule = molecule
if hasattr(molecule.solver, "chrgfield"):
self.chrgfield = molecule.solver.chrgfield
self.extra_nuc_energy = self.molecule.solver.ext_pot.computeNuclearEnergy(self.molecule.solver.mol)
else:
self.degenerate_mo_energies = np.any(np.isclose(molecule.mo_energies[1:], molecule.mo_energies[:-1]))
self.molecule = SecondQuantizedMolecule(xyz=molecule.xyz, q=molecule.q, spin=molecule.spin,
Expand Down Expand Up @@ -210,10 +214,20 @@ def simulate(self):
for swap_op in swap_ops:
wfn.Ca().rotate_columns(0, swap_op[0], swap_op[1], np.deg2rad(90))

if hasattr(self, "chrgfield"):
# TODO: Remove support for older version.
if self.backend.__version__ < "1.6":
self.backend.core.set_global_option_python('EXTERN', self.chrgfield.extern)
else:
energy, self.ciwfn = self.backend.energy('fci', molecule=self.molecule.solver.mol,
basis=self.basis, return_wfn=True,
ref_wfn=wfn, external_potentials=self.molecule.solver.external_potentials)
return energy + self.extra_nuc_energy

energy, self.ciwfn = self.backend.energy('fci', molecule=self.molecule.solver.mol,
basis=self.basis, return_wfn=True,
ref_wfn=wfn)
return energy
return energy + self.extra_nuc_energy

def get_rdm(self):
"""Compute the Full CI 1- and 2-particle reduced density matrices.
Expand Down
31 changes: 30 additions & 1 deletion tangelo/algorithms/classical/tests/test_ccsd_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

import unittest

import numpy as np

from tangelo import SecondQuantizedMolecule
from tangelo.algorithms.classical.ccsd_solver import CCSDSolver, default_ccsd_solver
from tangelo.molecule_library import mol_H2_321g, mol_Be_321g, mol_H4_sto3g_uhf_a1_frozen, xyz_H4
from tangelo.molecule_library import mol_H2_321g, mol_Be_321g, mol_H4_sto3g_uhf_a1_frozen, xyz_H4, xyz_Be, xyz_H2O


class CCSDSolverTest(unittest.TestCase):
Expand Down Expand Up @@ -59,6 +61,33 @@ def test_ccsd_be(self):

self.assertAlmostEqual(energy, -14.531416, places=5)

def test_ccsd_h2o_change_mo_coeff(self):
"""Test CCSDSolver against result from a reference implementation when rotating the molecular coefficients"""
mol = SecondQuantizedMolecule(xyz_H2O, q=0, spin=0, basis="sto-3g", frozen_orbitals=[6], symmetry=False)
mol_5 = SecondQuantizedMolecule(xyz_H2O, q=0, spin=0, basis="sto-3g", frozen_orbitals=[5], symmetry=False)
swap_mat = np.eye(mol.mo_coeff.shape[1])
swap_mat[6, 6] = 0.
swap_mat[5, 5] = 0.
swap_mat[6, 5] = 1.
swap_mat[5, 6] = 1.

solver = CCSDSolver(mol)
energy_before = solver.simulate()

solver_5 = CCSDSolver(mol_5)
energy_5 = solver_5.simulate()

# Swap orbital 6 and 5
mol.mo_coeff = mol.mo_coeff@swap_mat
energy = solver.simulate()
# Compare to SecondQunatizedMolecule with orbital 5 frozen
self.assertAlmostEqual(energy, energy_5, places=5)

# Swap back orbital 1 and 5
mol.mo_coeff = mol.mo_coeff@swap_mat
energy = solver.simulate()
self.assertAlmostEqual(energy, energy_before, places=5)

def test_ccsd_be_frozen_core(self):
""" Test CCSDSolver against result from reference implementation, with
no mean-field provided as input. Frozen core is considered.
Expand Down
29 changes: 28 additions & 1 deletion tangelo/algorithms/classical/tests/test_fci_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

import unittest

import numpy as np
from openfermion import get_sparse_operator

from tangelo import SecondQuantizedMolecule
from tangelo.algorithms import FCISolver
from tangelo.molecule_library import mol_H2_321g, mol_Be_321g, mol_H4_cation_sto3g, mol_H4_sto3g
from tangelo.toolboxes.qubit_mappings.mapping_transform import fermion_to_qubit_mapping
from tangelo.molecule_library import mol_H2_321g, mol_Be_321g, mol_H4_cation_sto3g, mol_H4_sto3g, xyz_H4


class FCISolverTest(unittest.TestCase):
Expand Down Expand Up @@ -81,6 +86,28 @@ def test_fci_H4_interior_frozen_orbitals(self):
one_rdm, two_rdm = solver.get_rdm()
self.assertAlmostEqual(energy, mol_H4_sto3g_freeze3.energy_from_rdms(one_rdm, two_rdm), places=5)

def test_fci_H4_modified_mo_coeff(self):
""" Test FCISolver against result from reference implementation with interior frozen orbitals by manually defining
a swap operation.
"""

mol = SecondQuantizedMolecule(xyz_H4, frozen_orbitals=[1, 3, 4])

unitary_mat = np.array([[ 0.99799630, -0.05866044, 0.02358562, 0.00246221],
[ 0.05673690, 0.99556613, 0.07416274, 0.01135272],
[-0.02767097, -0.07212301, 0.99605136, -0.04375241],
[-0.00431649, -0.01432819, 0.04272342, 0.99897486]])
# Modify orbitals
mol.mo_coeff = [email protected]_coeff

op = get_sparse_operator(fermion_to_qubit_mapping(mol.fermionic_hamiltonian, "JW")).toarray()
energy_op = np.linalg.eigh(op)[0][0]

solver = FCISolver(mol)
energy = solver.simulate()
self.assertAlmostEqual(energy, -1.8057990, places=5)
self.assertAlmostEqual(energy_op, -1.8057990, places=5)


if __name__ == "__main__":
unittest.main()
9 changes: 3 additions & 6 deletions tangelo/algorithms/projective/quantum_imaginary_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from tangelo.toolboxes.operators.operators import FermionOperator, QubitOperator
from tangelo.toolboxes.qubit_mappings.mapping_transform import fermion_to_qubit_mapping
from tangelo.toolboxes.ansatz_generator._general_unitary_cc import uccgsd_generator as uccgsd_pool
from tangelo.toolboxes.operators import qubitop_to_qubitham
from tangelo.toolboxes.qubit_mappings.statevector_mapping import get_reference_circuit
from tangelo.linq import Circuit, get_backend

Expand Down Expand Up @@ -128,7 +127,7 @@ def build(self):
up_then_down=self.up_then_down,
spin=0)

self.qubit_hamiltonian = qubitop_to_qubitham(qubit_op, self.qubit_mapping, self.up_then_down)
self.qubit_hamiltonian = qubit_op

# Getting the pool of operators for the ansatz. If more functionalities
# are added, this part must be modified and generalized.
Expand Down Expand Up @@ -179,10 +178,8 @@ def build(self):
for term in self.pool_operators:
self.pool_qubit_op += term

self.qubit_operator = self.qubit_hamiltonian.to_qubitoperator()

# Obtain all qubit terms that need to be measured
self.pool_h = [element*self.qubit_operator for element in self.pool_operators]
self.pool_h = [element*self.qubit_hamiltonian for element in self.pool_operators]
self.pool_pool = [[element1*element2 for element2 in self.pool_operators] for element1 in self.pool_operators]

# Obtain initial state preparation circuit
Expand Down Expand Up @@ -294,7 +291,7 @@ def energy_expectation(self, backend):
float: energy computed by the backend
"""
circuit = Circuit(n_qubits=self.final_circuit.width) if self.use_statevector else self.final_circuit
energy = backend.get_expectation_value(self.qubit_hamiltonian.to_qubitoperator(),
energy = backend.get_expectation_value(self.qubit_hamiltonian,
circuit,
initial_statevector=self.final_statevector)
return energy
Expand Down
18 changes: 9 additions & 9 deletions tangelo/algorithms/variational/iqcc_ilc_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,21 @@ def _update_ilc_solver(self, e_ilc):
if self.compress_qubit_ham:
self.ilc_ansatz.qubit_ham.frobenius_norm_compression(self.compress_eps, n_qubits)

# set dis, acs, and var_params to none to rebuild the dis & acs and initialize new parameters
self.ilc_ansatz.dis = None
self.ilc_ansatz.acs = None
self.ilc_ansatz.var_params = None
self.ilc_ansatz.build_circuit()

self.vqe_solver.qubit_hamiltonian = self.ilc_ansatz.qubit_ham
self.vqe_solver.initial_var_params = self.ilc_ansatz.var_params

if self.iteration == self.max_ilc_iter:
self.terminate_ilc = True
self.final_optimal_qmf_params = optimal_qmf_var_params
self.final_optimal_ilc_params = optimal_ilc_var_params
if self.verbose:
print(f"Terminating the ILC-VQE solver after {self.max_ilc_iter} iterations.")
else:
# Set dis, acs, and var_params to None to rebuild the dis & acs and initialize new parameters
self.ilc_ansatz.dis = None
self.ilc_ansatz.acs = None
self.ilc_ansatz.var_params = None
self.ilc_ansatz.build_circuit()

self.vqe_solver.qubit_hamiltonian = self.ilc_ansatz.qubit_ham
self.vqe_solver.initial_var_params = self.ilc_ansatz.var_params

def _update_qcc_solver(self, e_iqcc_ilc):
"""Updates after the final QCC energy evaluation with the final ILC dressed
Expand Down
Loading
Loading