Skip to content

Commit

Permalink
Introduced tests with CircBoxes
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloAndresCQ committed Sep 9, 2024
1 parent 10a322b commit 02162f4
Showing 1 changed file with 62 additions and 63 deletions.
125 changes: 62 additions & 63 deletions tests/test_structured_state_conditionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import numpy as np

from pytket.circuit import (
Bit,
Circuit,
CircBox,
OpType,
Qubit,
Bit,
if_not_bit,
reg_eq,
)
Expand Down Expand Up @@ -176,68 +177,66 @@ def test_circuit_with_conditional_gate_iv() -> None:
assert state.get_fidelity() == 1.0


# TODO: Currently not supporting CircBox, so these tests are omitted.
#
# def test_pytket_qir_conditional_8() -> None:
# c = Circuit(4)
# c.H(0)
# c.H(1)
# c.H(2)
# c.H(3)
# cbox = CircBox(c)
# d = Circuit(4)
# a = d.add_c_register("a", 4)
# d.add_circbox(cbox, [0, 2, 1, 3], condition=a[0])
#
# with CuTensorNetHandle() as libhandle:
# cfg = Config()
# state = simulate(libhandle, c, SimulationAlgorithm.MPSxGate, cfg)
# assert state.is_valid()
# assert np.isclose(state.vdot(state), 1.0, atol=cfg._atol)
# assert state.get_fidelity() == 1.0
#
#
# def test_pytket_qir_conditional_9() -> None:
# c = Circuit(4)
# c.X(0)
# c.Y(1)
# c.Z(2)
# c.H(3)
# cbox = CircBox(c)
# d = Circuit(4)
# a = d.add_c_register("a", 4)
# d.add_circbox(cbox, [0, 2, 1, 3], condition=a[0])
#
# with CuTensorNetHandle() as libhandle:
# cfg = Config()
# state = simulate(libhandle, c, SimulationAlgorithm.MPSxGate, cfg)
# assert state.is_valid()
# assert np.isclose(state.vdot(state), 1.0, atol=cfg._atol)
# assert state.get_fidelity() == 1.0
#
#
# def test_pytket_qir_conditional_10() -> None:
# box_circ = Circuit(4)
# box_circ.X(0)
# box_circ.Y(1)
# box_circ.Z(2)
# box_circ.H(3)
# box_c = box_circ.add_c_register("c", 5)
#
# box_circ.H(0)
# box_circ.add_classicalexpbox_register(box_c | box_c, box_c) # type: ignore
#
# cbox = CircBox(box_circ)
# d = Circuit(4, 5)
# a = d.add_c_register("a", 4)
# d.add_circbox(cbox, [0, 2, 1, 3, 0, 1, 2, 3, 4], condition=a[0])
#
# with CuTensorNetHandle() as libhandle:
# cfg = Config()
# state = simulate(libhandle, d, SimulationAlgorithm.MPSxGate, cfg)
# assert state.is_valid()
# assert np.isclose(state.vdot(state), 1.0, atol=cfg._atol)
# assert state.get_fidelity() == 1.0
def test_pytket_qir_conditional_8() -> None:
c = Circuit(4)
c.H(0)
c.H(1)
c.H(2)
c.H(3)
cbox = CircBox(c)
d = Circuit(4)
a = d.add_c_register("a", 4)
d.add_circbox(cbox, [0, 2, 1, 3], condition=a[0])

with CuTensorNetHandle() as libhandle:
cfg = Config()
state = simulate(libhandle, c, SimulationAlgorithm.MPSxGate, cfg)
assert state.is_valid()
assert np.isclose(state.vdot(state), 1.0, atol=cfg._atol)
assert state.get_fidelity() == 1.0


def test_pytket_qir_conditional_9() -> None:
c = Circuit(4)
c.X(0)
c.Y(1)
c.Z(2)
c.H(3)
cbox = CircBox(c)
d = Circuit(4)
a = d.add_c_register("a", 4)
d.add_circbox(cbox, [0, 2, 1, 3], condition=a[0])

with CuTensorNetHandle() as libhandle:
cfg = Config()
state = simulate(libhandle, c, SimulationAlgorithm.MPSxGate, cfg)
assert state.is_valid()
assert np.isclose(state.vdot(state), 1.0, atol=cfg._atol)
assert state.get_fidelity() == 1.0


def test_pytket_qir_conditional_10() -> None:
box_circ = Circuit(4)
box_circ.X(0)
box_circ.Y(1)
box_circ.Z(2)
box_circ.H(3)
box_c = box_circ.add_c_register("c", 5)

box_circ.H(0)
box_circ.add_classicalexpbox_register(box_c | box_c, box_c) # type: ignore

cbox = CircBox(box_circ)
d = Circuit(4, 5)
a = d.add_c_register("a", 4)
d.add_circbox(cbox, [0, 2, 1, 3, 0, 1, 2, 3, 4], condition=a[0])

with CuTensorNetHandle() as libhandle:
cfg = Config()
state = simulate(libhandle, d, SimulationAlgorithm.MPSxGate, cfg)
assert state.is_valid()
assert np.isclose(state.vdot(state), 1.0, atol=cfg._atol)
assert state.get_fidelity() == 1.0


def test_circuit_with_conditional_gate_v() -> None:
Expand Down

0 comments on commit 02162f4

Please sign in to comment.