Skip to content

Commit

Permalink
add test for basis_rotation_gates
Browse files Browse the repository at this point in the history
  • Loading branch information
damarkian committed Mar 25, 2024
1 parent 1f550d4 commit 1a706c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/qibochem/ansatz/basis_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def col_op(U, row, col):
U, row, col = move_step(U, row, col, 0, 1)
z, U = col_op(U, row, col)
z_array.append(z)
else:
break
#else:
# break
while col > 0:
U, row, col = move_step(U, row, col, -1, -1)
z, U = col_op(U, row, col)
Expand Down Expand Up @@ -234,8 +234,8 @@ def assign_element(A, row, col, k):
# print('jump left')
A, row, col, updown = jump_left(A, row, col, updown)
A, row, col = assign_element(A, row, col, k)
else:
raise ValueError("Bad direction")
#else:
# raise ValueError("Bad direction")

# print(row, col)
k += 1
Expand Down
26 changes: 26 additions & 0 deletions tests/test_basis_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,29 @@ def test_basis_rotation_layout():

A = basis_rotation.basis_rotation_layout(N)
assert np.allclose(A, ref_A)


def test_basis_rotation_gates():

mol = Molecule([("H", (0.0, 0.0, 0.0)), ("H", (0.0, 0.0, 0.9), ("H", (0.0, 0.0, 1.8)), 1, 1])
mol.run_pyscf(max_scf_cycles=100)
ham = mol.hamiltonian("sym", mol.oei, mol.tei, 0.0, "jw")

nqubits = mol.nso
occ = range(0, mol.nelec)
vir = range(mol.nelec, mol.nso)

U, theta = basis_rotation.unitary(occ, vir, parameters=0.1)
gate_angles, final_U = basis_rotation.givens_qr_decompose(U)
gate_layout = basis_rotation.basi_rotation_layout(nqubits)
gate_list, qubit_parameters = basis_rotation.basis_rotation_gates(gate_layout, gate_angles, theta)

circuit = Circuit(nqubits)
for _i in range(mol.nelec):
circuit.add(gates.X(_i))
circuit.add(gate_list)

vqe = models.VQE(circuit, ham)
assert np.isclose(vqe[0], mol.e_hf)


0 comments on commit 1a706c7

Please sign in to comment.