コード例 #1
0
def test_circuit_draw_callbacks(legend):
    """Check that callbacks are drawn correcly"""
    from qibo.callbacks import EntanglementEntropy
    entropy = EntanglementEntropy([0])
    c = Circuit(2)
    c.add(gates.CallbackGate(entropy))
    c.add(gates.H(0))
    c.add(gates.CallbackGate(entropy))
    c.add(gates.CNOT(0, 1))
    c.add(gates.CallbackGate(entropy))

    ref = 'q0: ─EE─H─EE─o─EE─\n' \
          'q1: ─EE───EE─X─EE─'

    if legend:
        ref += '\n\n Legend for callbacks and channels: \n' \
               '| Gate                | Symbol   |\n'\
               '|---------------------+----------|\n'\
               '| EntanglementEntropy | EE       |'

    assert c.draw(legend=legend) == ref
コード例 #2
0
def test_circuit_on_qubits_errors():
    smallc = Circuit(2)
    smallc.add((gates.H(i) for i in range(2)))
    with pytest.raises(ValueError):
        next(smallc.on_qubits(0, 1, 2))

    smallc = Circuit(2)
    smallc.add(gates.Flatten(4 * [0.5]))
    with pytest.raises(NotImplementedError):
        next(smallc.on_qubits(0, 1))

    from qibo.abstractions.callbacks import Callback
    smallc = Circuit(4)
    smallc.add(gates.CallbackGate(Callback()))
    with pytest.raises(NotImplementedError):
        next(smallc.on_qubits(0, 1, 2, 3))