Skip to content

Commit

Permalink
Separate refprep and Uprep (#259)
Browse files Browse the repository at this point in the history
* Separate refprep and Uprep
  • Loading branch information
JonathonMisiewicz authored May 21, 2024
1 parent a27d4cf commit 0a515a9
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/qforte/abc/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ def __init__(
)
self._ref = reference

self._Uprep = build_Uprep(self._ref, state_prep_type)
self._refprep = build_refprep(self._ref)
self._Uprep = qf.Circuit(self._refprep)

elif self._state_prep_type == "unitary_circ":
if not isinstance(reference, qf.Circuit):
raise ValueError("unitary_circ reference must be a Circuit.")

self._ref = system.hf_reference
self._refprep = build_refprep(self._ref)
self._Uprep = reference

else:
Expand Down
10 changes: 5 additions & 5 deletions src/qforte/abc/ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import qforte as qf

from qforte.utils.state_prep import build_Uprep
from qforte.utils.state_prep import build_refprep
from qforte.utils.trotterization import trotterize
from qforte.utils.compact_excitation_circuits import compact_excitation_circuit
from qforte.abc.mixin import Trotterizable
Expand Down Expand Up @@ -101,12 +101,12 @@ def build_orb_energies(self):
print("\nBuilding single-particle energies:")
print("---------------------------------------", flush=True)
qc = qf.Computer(self._nqb)
qc.apply_circuit(build_Uprep(self._ref, "occupation_list"))
qc.apply_circuit(self._refprep)
E0 = qc.direct_op_exp_val(self._qb_ham)

for i in range(self._nqb):
qc = qf.Computer(self._nqb)
qc.apply_circuit(build_Uprep(self._ref, "occupation_list"))
qc.apply_circuit(self._refprep)
qc.apply_gate(qf.gate("X", i, i))
Ei = qc.direct_op_exp_val(self._qb_ham)

Expand All @@ -119,7 +119,7 @@ def build_orb_energies(self):
self._orb_e.append(ei)

def get_res_over_mpdenom(self, residuals):
"""This function returns a vector given by the residuals dividied by the
"""This function returns a vector given by the residuals divided by the
respective Moller Plesset denominators.
Parameters
Expand All @@ -136,7 +136,7 @@ def get_res_over_mpdenom(self, residuals):
sq_op = self._pool_obj[m][1]

temp_idx = sq_op.terms()[0][2][-1]
if temp_idx < int(sum(self._ref) / 2): # if temp_idx is an occupied idx
if self._ref[temp_idx]: # if temp_idx is an occupied idx
sq_creators = sq_op.terms()[0][1]
sq_annihilators = sq_op.terms()[0][2]
else:
Expand Down
2 changes: 1 addition & 1 deletion src/qforte/ite/qite.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class QITE(Trotterizable, Algorithm):
solve the corresponding generailzed eigenvalue problem.
_Ekb : list of float
The list of after each additional time step.
The list of energies after each additional time step.
_expansion_type: {'complete_qubit', 'cqoy', 'SD', 'GSD', 'SDT', SDTQ', 'SDTQP', 'SDTQPH'}
The family of operators that each evolution operator :math:`\\hat{A}` will be built of.
Expand Down
1 change: 0 additions & 1 deletion src/qforte/ucc/adaptvqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ def update_ansatz(self):

curr_norm = 0.0
lgrst_grad = 0.0
Uvqc = self.build_Uvqc()

if self._verbose:
print(
Expand Down
2 changes: 1 addition & 1 deletion src/qforte/ucc/spqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def get_residual_vector(self, trial_amps):
# sq_op is 1.0(a^ b^ i j) - 1.0(j^ i^ b a)

qc_temp = qforte.Computer(self._nqb)
qc_temp.apply_circuit(self._Uprep)
qc_temp.apply_circuit(self._refprep)
qc_temp.apply_operator(sq_op.jw_transform(self._qubit_excitations))
sign_adjust = qc_temp.get_coeff_vec()[self._pool_idx_to_coeff_idx[m]]

Expand Down
2 changes: 1 addition & 1 deletion src/qforte/ucc/uccnpqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def fill_excited_dets(self):
I = excited_det.index()

qc_temp = qforte.Computer(self._nqb)
qc_temp.apply_circuit(self._Uprep)
qc_temp.apply_circuit(self._refprep)
qc_temp.apply_operator(sq_op.jw_transform(self._qubit_excitations))
phase_factor = qc_temp.get_coeff_vec()[I]

Expand Down
4 changes: 2 additions & 2 deletions src/qforte/utils/moment_energy_corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
DOI: 10.1063/1.481769
DOI: 10.1063/1.2137318
The use of such moment corrections in the UCC case is experimental
and a publication will appear in the future.
and preliminary data is published in 10.1021/acs.jpca.3c02781
"""

import qforte as qf
Expand Down Expand Up @@ -92,7 +92,7 @@ def construct_moment_space(self):
for i in self._mmcc_pool.terms():
sq_op = i[1]
qc = qf.Computer(self._nqb)
qc.apply_circuit(self._Uprep)
qc.apply_circuit(self._refprep)
# This could be replaced by set_bit?
qc.apply_operator(sq_op.jw_transform(self._qubit_excitations))
self._epstein_nesbet.append(qc.direct_op_exp_val(self._qb_ham))
Expand Down
15 changes: 6 additions & 9 deletions src/qforte/utils/state_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
import numpy as np


def build_Uprep(ref, state_prep_type):
Uprep = qforte.Circuit()
if state_prep_type == "occupation_list":
for j in range(len(ref)):
if ref[j] == 1:
Uprep.add(qforte.gate("X", j, j))
else:
raise ValueError("Only 'occupation_list' supported as state preparation type")
def build_refprep(ref):
refprep = qforte.Circuit()
for j, occupied in enumerate(ref):
if occupied:
refprep.add(qforte.gate("X", j, j))

return Uprep
return refprep


def ref_string(ref, nqb):
Expand Down

0 comments on commit 0a515a9

Please sign in to comment.