Skip to content

Commit 0a515a9

Browse files
Separate refprep and Uprep (#259)
* Separate refprep and Uprep
1 parent a27d4cf commit 0a515a9

File tree

8 files changed

+19
-21
lines changed

8 files changed

+19
-21
lines changed

src/qforte/abc/algorithm.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ def __init__(
8282
)
8383
self._ref = reference
8484

85-
self._Uprep = build_Uprep(self._ref, state_prep_type)
85+
self._refprep = build_refprep(self._ref)
86+
self._Uprep = qf.Circuit(self._refprep)
8687

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

9192
self._ref = system.hf_reference
93+
self._refprep = build_refprep(self._ref)
9294
self._Uprep = reference
9395

9496
else:

src/qforte/abc/ansatz.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import qforte as qf
1010

11-
from qforte.utils.state_prep import build_Uprep
11+
from qforte.utils.state_prep import build_refprep
1212
from qforte.utils.trotterization import trotterize
1313
from qforte.utils.compact_excitation_circuits import compact_excitation_circuit
1414
from qforte.abc.mixin import Trotterizable
@@ -101,12 +101,12 @@ def build_orb_energies(self):
101101
print("\nBuilding single-particle energies:")
102102
print("---------------------------------------", flush=True)
103103
qc = qf.Computer(self._nqb)
104-
qc.apply_circuit(build_Uprep(self._ref, "occupation_list"))
104+
qc.apply_circuit(self._refprep)
105105
E0 = qc.direct_op_exp_val(self._qb_ham)
106106

107107
for i in range(self._nqb):
108108
qc = qf.Computer(self._nqb)
109-
qc.apply_circuit(build_Uprep(self._ref, "occupation_list"))
109+
qc.apply_circuit(self._refprep)
110110
qc.apply_gate(qf.gate("X", i, i))
111111
Ei = qc.direct_op_exp_val(self._qb_ham)
112112

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

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

138138
temp_idx = sq_op.terms()[0][2][-1]
139-
if temp_idx < int(sum(self._ref) / 2): # if temp_idx is an occupied idx
139+
if self._ref[temp_idx]: # if temp_idx is an occupied idx
140140
sq_creators = sq_op.terms()[0][1]
141141
sq_annihilators = sq_op.terms()[0][2]
142142
else:

src/qforte/ite/qite.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class QITE(Trotterizable, Algorithm):
9696
solve the corresponding generailzed eigenvalue problem.
9797
9898
_Ekb : list of float
99-
The list of after each additional time step.
99+
The list of energies after each additional time step.
100100
101101
_expansion_type: {'complete_qubit', 'cqoy', 'SD', 'GSD', 'SDT', SDTQ', 'SDTQP', 'SDTQPH'}
102102
The family of operators that each evolution operator :math:`\\hat{A}` will be built of.

src/qforte/ucc/adaptvqe.py

-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ def update_ansatz(self):
379379

380380
curr_norm = 0.0
381381
lgrst_grad = 0.0
382-
Uvqc = self.build_Uvqc()
383382

384383
if self._verbose:
385384
print(

src/qforte/ucc/spqe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def get_residual_vector(self, trial_amps):
403403
# sq_op is 1.0(a^ b^ i j) - 1.0(j^ i^ b a)
404404

405405
qc_temp = qforte.Computer(self._nqb)
406-
qc_temp.apply_circuit(self._Uprep)
406+
qc_temp.apply_circuit(self._refprep)
407407
qc_temp.apply_operator(sq_op.jw_transform(self._qubit_excitations))
408408
sign_adjust = qc_temp.get_coeff_vec()[self._pool_idx_to_coeff_idx[m]]
409409

src/qforte/ucc/uccnpqe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def fill_excited_dets(self):
240240
I = excited_det.index()
241241

242242
qc_temp = qforte.Computer(self._nqb)
243-
qc_temp.apply_circuit(self._Uprep)
243+
qc_temp.apply_circuit(self._refprep)
244244
qc_temp.apply_operator(sq_op.jw_transform(self._qubit_excitations))
245245
phase_factor = qc_temp.get_coeff_vec()[I]
246246

src/qforte/utils/moment_energy_corrections.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
DOI: 10.1063/1.481769
88
DOI: 10.1063/1.2137318
99
The use of such moment corrections in the UCC case is experimental
10-
and a publication will appear in the future.
10+
and preliminary data is published in 10.1021/acs.jpca.3c02781
1111
"""
1212

1313
import qforte as qf
@@ -92,7 +92,7 @@ def construct_moment_space(self):
9292
for i in self._mmcc_pool.terms():
9393
sq_op = i[1]
9494
qc = qf.Computer(self._nqb)
95-
qc.apply_circuit(self._Uprep)
95+
qc.apply_circuit(self._refprep)
9696
# This could be replaced by set_bit?
9797
qc.apply_operator(sq_op.jw_transform(self._qubit_excitations))
9898
self._epstein_nesbet.append(qc.direct_op_exp_val(self._qb_ham))

src/qforte/utils/state_prep.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
import numpy as np
33

44

5-
def build_Uprep(ref, state_prep_type):
6-
Uprep = qforte.Circuit()
7-
if state_prep_type == "occupation_list":
8-
for j in range(len(ref)):
9-
if ref[j] == 1:
10-
Uprep.add(qforte.gate("X", j, j))
11-
else:
12-
raise ValueError("Only 'occupation_list' supported as state preparation type")
5+
def build_refprep(ref):
6+
refprep = qforte.Circuit()
7+
for j, occupied in enumerate(ref):
8+
if occupied:
9+
refprep.add(qforte.gate("X", j, j))
1310

14-
return Uprep
11+
return refprep
1512

1613

1714
def ref_string(ref, nqb):

0 commit comments

Comments
 (0)