예제 #1
0
def test_pauli_decomposition_3_qubit(measurement):
    a1 = cirq.NamedQubit('a1')
    a2 = cirq.NamedQubit('a2')
    a3 = cirq.NamedQubit('a3')
    for qubits in [[a1, a2, a3], [a3, a1, a2], [a2, a3, a1]]:
        decomp = pauli_decomposition(measurement, qubits)
        assert np.allclose(measurement, decomp.matrix(qubits))
예제 #2
0
def test_pauli_decomposition_measurement_from_vectors(vector, expected_str):
    a1 = cirq.NamedQubit('a1')
    a2 = cirq.NamedQubit('a2')
    col = np.sqrt(0.5) * np.array(vector).reshape(4,1)
    measurement = col.dot(col.T.conj())
    decomp = pauli_decomposition(measurement, [a1, a2])
    assert f"{decomp:.3f}" == expected_str
예제 #3
0
def test_pauli_decomposition_wrong_inputs():
    a1 = cirq.NamedQubit('a1')
    a2 = cirq.NamedQubit('a2')
    H_not_2d = [[[0.5+0.j,  0. +0.5j],
                 [0. -0.5j,  0.5+0.j]]]
    H_not_square = [[0.5+0.j,  0. +0.5j],
                    [0. -0.5j]]
    H_good = [[0.5+0.j,  0. +0.5j],
              [0. -0.5j,  0.5+0.j]]
    with pytest.raises(ValueError, match='pauli_decomposition expects a 2-d square matrix.'):
        pauli_decomposition(H_not_2d, [a1])

    with pytest.raises(ValueError, match='pauli_decomposition expects a 2-d square matrix.'):
        pauli_decomposition(H_not_square, [a1])
        
    with pytest.raises(ValueError, match=re.escape('pauli_decomposition: Expect that size_of_matrix==pow(2, number_of_qubits). In your case 2!=pow(2, 2).')):
        pauli_decomposition(H_good, [a1, a2])
예제 #4
0
def test_pauli_decomposition_1_qubit(measurement):
    a1 = cirq.NamedQubit('a1')
    decomp = pauli_decomposition(measurement, [a1])
    assert np.allclose(measurement, decomp.matrix([a1]))