Skip to content

Commit

Permalink
Add tests for non-JW map in ucc.py
Browse files Browse the repository at this point in the history
  • Loading branch information
chmwzc committed Dec 19, 2023
1 parent b344e33 commit fa5ee3f
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion tests/test_ucc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest
from qibo import gates
from scipy.optimize import minimize

from qibochem.ansatz.hf_reference import hf_circuit
Expand Down Expand Up @@ -92,7 +93,7 @@ def test_uccsd():
except ModuleNotFoundError:
mol.run_psi4()

# Apply embedding and boson encoding
# Apply embedding
mol.hf_embedding(active=[1, 5])
hamiltonian = mol.hamiltonian(oei=mol.embed_oei, tei=mol.embed_tei, constant=mol.inactive_energy)

Expand Down Expand Up @@ -164,3 +165,47 @@ def electronic_energy(parameters):
lih_uccsd_energy = -7.847535097575567

assert vqe.fun == pytest.approx(lih_uccsd_energy)


def test_ucc_bk():
"""Build a UCC-BK circuit"""
# Control
gate_list = [
gates.H(0),
gates.RX(1, -0.5 * np.pi, trainable=False),
gates.H(2),
gates.CNOT(2, 1),
gates.CNOT(1, 0),
gates.RZ(0, 0.0),
gates.CNOT(1, 0),
gates.CNOT(2, 1),
gates.H(0),
gates.RX(1, -0.5 * np.pi, trainable=False),
gates.H(2),
gates.RX(0, -0.5 * np.pi, trainable=False),
gates.RX(1, -0.5 * np.pi, trainable=False),
gates.RX(2, -0.5 * np.pi, trainable=False),
gates.CNOT(2, 1),
gates.CNOT(1, 0),
gates.RZ(0, 0.0),
gates.CNOT(1, 0),
gates.CNOT(2, 1),
gates.RX(0, -0.5 * np.pi, trainable=False),
gates.RX(1, -0.5 * np.pi, trainable=False),
gates.RX(2, -0.5 * np.pi, trainable=False),
]
# Test ucc_function
circuit = ucc_circuit(4, [0, 2], ferm_qubit_map="bk")
# Check gates are correct
assert all(
control.name == test.name and control.target_qubits == test.target_qubits
for control, test in zip(gate_list, circuit.queue)
)
# Check that only two parametrised gates
assert len(circuit.get_parameters()) == 2


def test_ucc_ferm_qubit_map_error():
"""If unknown fermion to qubit map used"""
with pytest.raises(KeyError):
ucc_circuit(2, [0, 1], "Unknown")

0 comments on commit fa5ee3f

Please sign in to comment.