Example #1
0
def test_swap_gate():
	gate = _gates.SwapGate()
	assert gate == gate.get_inverse()
	assert str(gate) == "Swap"
	assert gate.interchangeable_qubit_indices == [[0, 1]]
	assert np.array_equal(gate.matrix, 
	       np.matrix([[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]))
	assert isinstance(_gates.Swap, _gates.SwapGate)
Example #2
0
def test_sqrtswap_gate():
    sqrt_gate = _gates.SqrtSwapGate()
    swap_gate = _gates.SwapGate()
    assert str(sqrt_gate) == "SqrtSwap"
    assert np.array_equal(sqrt_gate.matrix * sqrt_gate.matrix,
                          swap_gate.matrix)
    assert np.array_equal(
        sqrt_gate.matrix,
        np.matrix([[1, 0, 0, 0], [0, 0.5 + 0.5j, 0.5 - 0.5j, 0],
                   [0, 0.5 - 0.5j, 0.5 + 0.5j, 0], [0, 0, 0, 1]]))
    assert isinstance(_gates.SqrtSwap, _gates.SqrtSwapGate)