Exemple #1
0
def test_basic_rotation_gate_get_merged():
	basic_gate = _basics.BasicGate()
	basic_rotation_gate1 = _basics.BasicRotationGate(0.5)
	basic_rotation_gate2 = _basics.BasicRotationGate(1.0)
	basic_rotation_gate3 = _basics.BasicRotationGate(1.5)
	with pytest.raises(_basics.NotMergeable):
		basic_rotation_gate1.get_merged(basic_gate)
	merged_gate = basic_rotation_gate1.get_merged(basic_rotation_gate2)
	assert merged_gate == basic_rotation_gate3
Exemple #2
0
def test_basic_rotation_gate_is_identity():
    basic_rotation_gate1 = _basics.BasicRotationGate(0.0)
    basic_rotation_gate2 = _basics.BasicRotationGate(1.0 * math.pi)
    basic_rotation_gate3 = _basics.BasicRotationGate(2.0 * math.pi)
    basic_rotation_gate4 = _basics.BasicRotationGate(3.0 * math.pi)
    basic_rotation_gate5 = _basics.BasicRotationGate(4.0 * math.pi)
    assert basic_rotation_gate1.is_identity()
    assert not basic_rotation_gate2.is_identity()
    assert not basic_rotation_gate3.is_identity()
    assert not basic_rotation_gate4.is_identity()
    assert basic_rotation_gate5.is_identity()
Exemple #3
0
def test_comparing_different_gates(main_engine):
	basic_gate = _basics.BasicGate()
	basic_rotation_gate = _basics.BasicRotationGate(1.0)
	self_inverse_gate = _basics.SelfInverseGate()
	assert not basic_gate == basic_rotation_gate
	assert not basic_gate == self_inverse_gate
	assert not self_inverse_gate == basic_rotation_gate
Exemple #4
0
def test_basic_rotation_gate_comparison():
    basic_rotation_gate1 = _basics.BasicRotationGate(0.5)
    basic_rotation_gate2 = _basics.BasicRotationGate(0.5)
    basic_rotation_gate3 = _basics.BasicRotationGate(0.5 + 4 * math.pi)
    assert basic_rotation_gate1 == basic_rotation_gate2
    assert basic_rotation_gate1 == basic_rotation_gate3
    basic_rotation_gate4 = _basics.BasicRotationGate(0.50000001)
    # Test __ne__:
    assert basic_rotation_gate4 != basic_rotation_gate1
    # Test one gate close to 4*pi the other one close to 0
    basic_rotation_gate5 = _basics.BasicRotationGate(1.e-13)
    basic_rotation_gate6 = _basics.BasicRotationGate(4 * math.pi - 1.e-13)
    assert basic_rotation_gate5 == basic_rotation_gate6
    # Test different types of gates
    basic_gate = _basics.BasicGate()
    assert not basic_gate == basic_rotation_gate6
    assert basic_rotation_gate2 != _basics.BasicRotationGate(0.5 + 2 * math.pi)
Exemple #5
0
def test_basic_rotation_gate_get_inverse(input_angle, inverse_angle):
	basic_rotation_gate = _basics.BasicRotationGate(input_angle)
	inverse = basic_rotation_gate.get_inverse()
	assert isinstance(inverse, _basics.BasicRotationGate)
	assert inverse._angle == pytest.approx(inverse_angle)
Exemple #6
0
def test_basic_rotation_gate_str():
	basic_rotation_gate = _basics.BasicRotationGate(0.5)
	assert str(basic_rotation_gate) == "BasicRotationGate(0.5)"
Exemple #7
0
def test_basic_rotation_gate_init(input_angle, modulo_angle):
	# Test internal representation
	gate = _basics.BasicRotationGate(input_angle)
	assert gate._angle == pytest.approx(modulo_angle)
Exemple #8
0
def test_basic_rotation_tex_str():
    gate = _basics.BasicRotationGate(0.5 * math.pi)
    assert gate.tex_str() == "BasicRotationGate$_{0.5\\pi}$"
    gate = _basics.BasicRotationGate(4 * math.pi - 1e-13)
    assert gate.tex_str() == "BasicRotationGate$_{0.0\\pi}$"
Exemple #9
0
def test_basic_rotation_gate_str():
    gate = _basics.BasicRotationGate(math.pi)
    assert str(gate) == "BasicRotationGate(3.14159265359)"
    assert gate.to_string(symbols=True) == u"BasicRotationGate(1.0π)"
    assert gate.to_string(symbols=False) == "BasicRotationGate(3.14159265359)"
def test_basic_rotation_tex_str():
    basic_rotation_gate = _basics.BasicRotationGate(0.5)
    assert basic_rotation_gate.tex_str() == "BasicRotationGate$_{0.5}$"
    basic_rotation_gate = _basics.BasicRotationGate(4 * math.pi - 1e-13)
    assert basic_rotation_gate.tex_str() == "BasicRotationGate$_{0.0}$"
Exemple #11
0
def test_basic_rotation_tex_str():
    basic_rotation_gate = _basics.BasicRotationGate(0.5)
    assert basic_rotation_gate.tex_str() == "BasicRotationGate$_{0.5}$"