def test_angled_gate_with_expr():
    expr = FreeParameterExpression(FreeParameter("theta") + 1)
    new_expr = expr.subs({"theta": 1})
    gate = AngledGate(angle=new_expr, qubit_count=1, ascii_symbols=["bar"])
    expected = AngledGate(angle=2, qubit_count=1, ascii_symbols=["bar"])

    assert gate == expected
def test_adjoint_parameterized():
    theta = FreeParameter("theta")
    angled_gate = AngledGate(angle=(theta + 1),
                             qubit_count=1,
                             ascii_symbols=["foo"])
    assert angled_gate.adjoint() == [
        AngledGate(angle=-(theta + 1), qubit_count=1, ascii_symbols=["foo"])
    ]
Beispiel #3
0
def test_equality(angled_gate):
    gate = AngledGate(angle=0.15, qubit_count=1, ascii_symbols=["bar"])
    other_gate = AngledGate(angle=0.3, qubit_count=1, ascii_symbols=["foo"])
    non_gate = "non gate"

    assert angled_gate == gate
    assert angled_gate is not gate
    assert angled_gate != other_gate
    assert angled_gate != non_gate
def test_symbolic_equality():
    symbol1 = FreeParameter("theta")
    symbol2 = FreeParameter("phi")
    symbol3 = FreeParameter("theta")
    gate1 = AngledGate(angle=symbol1, qubit_count=1, ascii_symbols=["bar"])
    gate2 = AngledGate(angle=symbol1, qubit_count=1, ascii_symbols=["bar"])
    gate3 = AngledGate(angle=symbol3, qubit_count=1, ascii_symbols=["bar"])
    other_gate = AngledGate(angle=symbol2,
                            qubit_count=1,
                            ascii_symbols=["foo"])

    assert gate1 == gate2
    assert gate1 == gate3
    assert gate1 is not gate2
    assert gate1 != other_gate
def test_getters():
    qubit_count = 2
    ascii_symbols = ("foo", "bar")
    angle = 0.15
    gate = AngledGate(angle=angle, qubit_count=qubit_count, ascii_symbols=ascii_symbols)

    assert gate.qubit_count == qubit_count
    assert gate.ascii_symbols == ascii_symbols
    assert gate.angle == angle
Beispiel #6
0
def test_np_float_angle_json():
    angled_gate = AngledGate(angle=np.float32(0.15),
                             qubit_count=1,
                             ascii_symbols=["foo"])
    angled_gate_json = BaseModel.construct(target=[0],
                                           angle=angled_gate.angle).json()
    match = re.match(r'\{"target": \[0], "angle": (\d*\.?\d*)}',
                     angled_gate_json)
    angle_value = float(match.group(1))
    assert angle_value == angled_gate.angle
Beispiel #7
0
def test_angle_is_none():
    AngledGate(qubit_count=1, ascii_symbols=["foo"], angle=None)
Beispiel #8
0
def angled_gate():
    return AngledGate(angle=0.15, qubit_count=1, ascii_symbols=["foo"])
def test_mixed_angle_equality():
    symbol1 = FreeParameter("theta")
    gate1 = AngledGate(angle=symbol1, qubit_count=1, ascii_symbols=["bar"])
    gate2 = AngledGate(angle=0.15, qubit_count=1, ascii_symbols=["foo"])

    assert gate1 != gate2
def test_adjoint(angled_gate):
    assert angled_gate.adjoint() == [
        AngledGate(angle=-0.15, qubit_count=1, ascii_symbols=["foo"])
    ]
def test_bind_values():
    theta = FreeParameter("theta")
    gate = AngledGate(angle=theta, qubit_count=1, ascii_symbols=["bar"])
    gate.bind_values(theta=1)