Skip to content

Commit

Permalink
add test_swap_matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
damarkian committed Dec 14, 2023
1 parent 55048de commit 46ec84f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tests/test_basis_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,32 @@
from qibochem.driver.molecule import Molecule
from qibochem.measurement.expectation import expectation

def test_swap_matrices():
"""Test for swap_matrices"""
permutations = [[(0,1),(2,3)]]
n_qubits = 4
smat = basis_rotation.swap_matrices(permutations, n_qubits)
ref_smat = np.array([[0., 1., 0., 0.],
[1., 0., 0., 0.],
[0., 0., 0., 1.],
[0., 0., 1., 0.]])

assert np.allclose(smat, ref_smat)


def test_unitary_rot_matrix():
"""Test for unitary rotation matrix"""
occ = [0]
vir = [1, 2]
parameters = np.zeros(len(occ) * len(vir))
parameters = np.zeros(len(occ)*len(vir))
parameters += 0.1
u = basis_rotation.unitary_rot_matrix(parameters, occ, vir)
ref_u = np.array(
[[0.99001666, 0.099667, 0.099667], [-0.099667, 0.99500833, -0.00499167], [-0.099667, -0.00499167, 0.99500833]]
)

ref_u = np.array([[ 0.99001666, 0.099667, 0.099667],
[-0.099667, 0.99500833, -0.00499167],
[-0.099667, -0.00499167, 0.99500833]])
assert np.allclose(u, ref_u)


def test_br_ansatz():
"""Test of basis rotation ansatz against hardcoded HF energies"""
h2_ref_energy = -1.117349035
Expand Down
1 change: 1 addition & 0 deletions tests/test_ucc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest
from scipy.optimize import minimize

from qibochem.ansatz.hf_reference import hf_circuit
Expand Down

0 comments on commit 46ec84f

Please sign in to comment.