def test_circuit_draw_channels(legend): """Check that channels are drawn correctly""" from qibo.models import Circuit as circuit c = circuit(2, density_matrix=True) c.add(gates.H(0)) c.add(gates.PauliNoiseChannel(0, 0.1, 0.0, 0.2)) c.add(gates.H(1)) c.add(gates.PauliNoiseChannel(1, 0.0, 0.2, 0.1)) c.add(gates.CNOT(0, 1)) c.add(gates.PauliNoiseChannel(0, 0.1, 0.0, 0.2)) c.add(gates.PauliNoiseChannel(1, 0.0, 0.2, 0.1)) ref = 'q0: ─H─PN─o─PN─\n' \ 'q1: ─H─PN─X─PN─' if legend: ref += '\n\n Legend for callbacks and channels: \n' \ '| Gate | Symbol |\n' \ '|-------------------+----------|\n' \ '| PauliNoiseChannel | PN |' assert c.draw(legend=legend) == ref
def test_circuit_with_noise(measurements, noise_map): c = Circuit(2) c.add([gates.H(0), gates.H(1), gates.CNOT(0, 1)]) if measurements: c.add(gates.M(0, 1)) noisyc = c.with_noise(noise_map) if not isinstance(noise_map, dict): noise_map = {0: noise_map, 1: noise_map} targetc = Circuit(2) targetc.add(gates.H(0)) targetc.add(gates.PauliNoiseChannel(0, *noise_map[0])) targetc.add(gates.H(1)) targetc.add(gates.PauliNoiseChannel(1, *noise_map[1])) targetc.add(gates.CNOT(0, 1)) targetc.add(gates.PauliNoiseChannel(0, *noise_map[0])) targetc.add(gates.PauliNoiseChannel(1, *noise_map[1])) for g1, g2 in zip(noisyc.queue, targetc.queue): assert isinstance(g1, g2.__class__) assert g1.target_qubits == g2.target_qubits assert g1.control_qubits == g2.control_qubits if measurements: assert noisyc.measurement_gate.target_qubits == (0, 1) assert noisyc.measurement_tuples == {"register0": (0, 1)}
def test_pauli_noise_channel_init(): gate = gates.PauliNoiseChannel(0, 0.1, 0.2, 0.3) assert gate.target_qubits == (0,) assert isinstance(gate.gates[0], gates.X) assert isinstance(gate.gates[1], gates.Y) assert isinstance(gate.gates[2], gates.Z)