Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathonMisiewicz committed May 20, 2024
1 parent 3af1661 commit 9de4f17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/qforte/abc/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
self._state_prep_type = state_prep_type

if self._state_prep_type == "occupation_list":
if reference == None:
if reference is None:
self._ref = system.hf_reference
else:
if not (isinstance(reference, list)):
Expand Down
24 changes: 23 additions & 1 deletion tests/test_slow_qk.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pytest import approx
from qforte import Circuit, build_circuit, QubitOperator, Molecule, MRSQK, SRQK
from qforte import Circuit, build_circuit, QubitOperator, Molecule, MRSQK, SRQK, gate


class TestPhysicalQKD:
Expand Down Expand Up @@ -394,6 +394,7 @@ def test_H4_physical_qkd(self):
# make test with algorithm class
mol = Molecule()
mol.hamiltonian = H4_qubit_hamiltonian
mol.hf_reference = ref.copy()

# SRQK
alg1 = SRQK(mol, reference=ref, trotter_number=1, fast=False)
Expand All @@ -402,3 +403,24 @@ def test_H4_physical_qkd(self):

Egs1_fast = -1.9982299799
assert Egs1 == approx(Egs1_fast, abs=1.0e-9)

ref = Circuit()
ref.add_gate(gate("X", 0, 0))
ref.add_gate(gate("X", 1, 1))
ref.add_gate(gate("X", 2, 2))
ref.add_gate(gate("X", 3, 3))
ref.add_gate(gate("Ry", 0, 0, 0.1))
ref.add_gate(gate("Ry", 1, 1, 0.1))

alg2 = SRQK(
mol,
reference=ref,
trotter_number=1,
fast=False,
state_prep_type="unitary_circ",
)
alg2.run(s=3)
Egs2 = alg2.get_gs_energy()

Egs2_fast = -1.9977703813619807
assert Egs2 == approx(Egs2_fast, abs=1.0e-9)

0 comments on commit 9de4f17

Please sign in to comment.