Skip to content

Commit

Permalink
One test file
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikandreasseitz committed Nov 15, 2023
1 parent 31f0d9d commit 53357c2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 75 deletions.
24 changes: 0 additions & 24 deletions tests/test_bell_states.py

This file was deleted.

57 changes: 57 additions & 0 deletions tests/test_gates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from __future__ import annotations

import jax.numpy as jnp
import pytest

from horqrux.gates import NOT, SWAP, H, Rx, Ry, Rz, X, Y, Z
from horqrux.ops import apply_gate
from horqrux.utils import equivalent_state, prepare_state


@pytest.mark.parametrize(
["init_state", "final_state"],
[
("00", 1 / jnp.sqrt(2) * jnp.array([1, 0, 0, 1])),
("01", 1 / jnp.sqrt(2) * jnp.array([0, 1, 1, 0])),
("11", 1 / jnp.sqrt(2) * jnp.array([0, 1, -1, 0])),
("10", 1 / jnp.sqrt(2) * jnp.array([1, 0, 0, -1])),
],
)
def test_bell_states(init_state, final_state):
state = prepare_state(len(init_state), init_state)
state = apply_gate(state, H(target_idx=0))
state = apply_gate(state, NOT(target_idx=1, control_idx=0))
assert jnp.allclose(state.flatten(), final_state)


@pytest.mark.parametrize(
"x",
[
("10", "01", SWAP(target_idx=(0, 1))),
("00", "00", SWAP(target_idx=(0, 1))),
("001", "100", SWAP(target_idx=(0, 2))),
("011", "110", SWAP(target_idx=(0, 2), control_idx=1)),
("001", "001", SWAP(target_idx=(0, 2), control_idx=1)),
("00101", "01100", SWAP(target_idx=(4, 1), control_idx=2)),
("1001001", "1000011", SWAP(target_idx=(5, 3), control_idx=(6, 0))),
],
)
def test_swap_gate(x):
init_state, expected_state, op = x
state = prepare_state(len(init_state), init_state)
out_state = apply_gate(state, op)
assert equivalent_state(out_state, expected_state), "Output states not similar."


@pytest.mark.skip
def test_single_gates():
# horqrux
state = prepare_state(7)
state = apply_gate(state, X(0))
state = apply_gate(state, Y(1))
state = apply_gate(state, Z(2))
state = apply_gate(state, H(3))
state = apply_gate(state, Rx(1 / 4 * jnp.pi, 4))
state = apply_gate(state, Ry(1 / 3 * jnp.pi, 5))
state = apply_gate(state, Rz(1 / 2 * jnp.pi, 6))
# FIXME
26 changes: 0 additions & 26 deletions tests/test_multi_qubit_gate.py

This file was deleted.

25 changes: 0 additions & 25 deletions tests/test_single_gates.py

This file was deleted.

0 comments on commit 53357c2

Please sign in to comment.