Exemplo n.º 1
0
def test_on_each_multiple_qubits_bad_qubits_shape():
    real_cnot = np.zeros(shape=(16, 16))
    qubits = [cirq.LineQubit.range(3)]
    with pytest.raises(
        ValueError, match="Number of qubits in each register should be"
    ):
        NoisyOperation.on_each(cirq.CNOT, qubits=qubits, real=real_cnot)
Exemplo n.º 2
0
def test_on_each_bad_types():
    ideal = cirq.Circuit(cirq.I(cirq.LineQubit(0)))
    real = np.identity(4)
    with pytest.raises(TypeError, match="must be iterable"):
        NoisyOperation.on_each(ideal,
                               qubits=cirq.NamedQubit("new"),
                               channel_matrix=real)
Exemplo n.º 3
0
def test_on_each_multiple_qubits(qubits, real):
    noisy_ops = NoisyOperation.on_each(cirq.CNOT, qubits=qubits, real=real)
    assert len(noisy_ops) == 2

    for i, op in enumerate(noisy_ops):
        if real is not None:
            assert np.allclose(op.real_matrix, real)
        assert op.num_qubits == 2
        assert set(op.qubits) == set(qubits[i])
Exemplo n.º 4
0
def test_on_each_single_qubit(qreg, real):
    noisy_ops = NoisyOperation.on_each(cirq.X, qubits=qreg, real=real)

    assert len(noisy_ops) == len(qreg)

    for i, op in enumerate(noisy_ops):
        if real is not None:
            assert np.allclose(op.real_matrix, real)
        assert op.num_qubits == 1
        assert list(op.ideal_circuit().all_qubits())[0] == qreg[i]