Skip to content

Commit

Permalink
add more gates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Sep 21, 2023
1 parent 3d57fea commit 5f86507
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions tests/gates/gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
import itertools

import numpy as np
import pytest
import scipy.sparse.linalg

import ffsim


def test_apply_givens_rotation():
@pytest.mark.parametrize(
"norb, nelec",
[
(2, (1, 1)),
(4, (2, 2)),
(5, (3, 2)),
],
)
def test_apply_givens_rotation(norb: int, nelec: tuple[int, int]):
"""Test applying Givens rotation."""
norb = 5
n_alpha = 3
n_beta = 2
nelec = (n_alpha, n_beta)

dim = ffsim.dim(norb, nelec)
rng = np.random.default_rng()
vec = np.array(ffsim.random.random_statevector(dim, seed=rng))
Expand All @@ -49,13 +53,16 @@ def test_apply_givens_rotation():
np.testing.assert_allclose(vec, original_vec)


def test_apply_tunneling_interaction():
@pytest.mark.parametrize(
"norb, nelec",
[
(2, (1, 1)),
(4, (2, 2)),
(5, (3, 2)),
],
)
def test_apply_tunneling_interaction(norb: int, nelec: tuple[int, int]):
"""Test applying tunneling interaction."""
norb = 5
n_alpha = 3
n_beta = 2
nelec = (n_alpha, n_beta)

dim = ffsim.dim(norb, nelec)
rng = np.random.default_rng()
vec = np.array(ffsim.random.random_statevector(dim, seed=rng))
Expand All @@ -78,13 +85,16 @@ def test_apply_tunneling_interaction():
np.testing.assert_allclose(result, expected, atol=1e-8)


def test_apply_num_interaction():
@pytest.mark.parametrize(
"norb, nelec",
[
(2, (1, 1)),
(4, (2, 2)),
(5, (3, 2)),
],
)
def test_apply_num_interaction(norb: int, nelec: tuple[int, int]):
"""Test applying number interaction."""
norb = 5
n_alpha = 3
n_beta = 2
nelec = (n_alpha, n_beta)

dim = ffsim.dim(norb, nelec)
rng = np.random.default_rng()
vec = np.array(ffsim.random.random_statevector(dim, seed=rng))
Expand All @@ -104,24 +114,24 @@ def test_apply_num_interaction():
np.testing.assert_allclose(result, expected, atol=1e-8)


def test_apply_num_num_interaction():
@pytest.mark.parametrize(
"norb, nelec",
[
(2, (1, 1)),
(4, (2, 2)),
(5, (3, 2)),
],
)
def test_apply_num_num_interaction(norb: int, nelec: tuple[int, int]):
"""Test applying number-number interaction."""
norb = 5

rng = np.random.default_rng()
n_alpha = 3
n_beta = 2
occupied_orbitals = (
rng.choice(norb, n_alpha, replace=False),
rng.choice(norb, n_beta, replace=False),
)
nelec = tuple(len(orbs) for orbs in occupied_orbitals)
occupied_orbitals = ffsim.testing.random_occupied_orbitals(norb, nelec)
vec = ffsim.slater_determinant(norb, occupied_orbitals)

theta = rng.standard_normal()
for i, j in itertools.combinations_with_replacement(range(norb), 2):
for spin_i, spin_j in itertools.product(range(2), repeat=2):
target_orbs = (set(), set())
target_orbs: tuple[set[int], set[int]] = (set(), set())
target_orbs[spin_i].add(i)
target_orbs[spin_j].add(j)
alpha_orbs, beta_orbs = target_orbs
Expand Down

0 comments on commit 5f86507

Please sign in to comment.