Exemplo n.º 1
0
def test_tensor_or():
    saving_backend = DummyEngine(save_commands=True)
    main_engine = MainEngine(backend=saving_backend,
                             engine_list=[DummyEngine()])
    gate = Rx(0.6)
    qubit0 = Qubit(main_engine, 0)
    qubit1 = Qubit(main_engine, 1)
    qubit2 = Qubit(main_engine, 2)
    # Option 1:
    _metagates.Tensor(gate) | ([qubit0, qubit1, qubit2], )
    # Option 2:
    _metagates.Tensor(gate) | [qubit0, qubit1, qubit2]
    received_commands = []
    # Remove Allocate and Deallocate gates
    for cmd in saving_backend.received_commands:
        if not (isinstance(cmd.gate, FastForwardingGate)
                or isinstance(cmd.gate, ClassicalInstructionGate)):
            received_commands.append(cmd)
    # Check results
    assert len(received_commands) == 6
    qubit_ids = []
    for cmd in received_commands:
        assert len(cmd.qubits) == 1
        assert cmd.gate == gate
        qubit_ids.append(cmd.qubits[0][0].id)
    assert sorted(qubit_ids) == [0, 0, 1, 1, 2, 2]
Exemplo n.º 2
0
def test_tensored_gate_invalid():
    qb0 = WeakQubitRef(None, idx=0)
    qb1 = WeakQubitRef(None, idx=1)

    with pytest.raises(ValueError):
        _metagates.Tensor(Y) | (qb0, qb1)

    with pytest.raises(ValueError):
        _metagates.Tensor(Y) | qb0
Exemplo n.º 3
0
def test_tensor_comparison():
    gate1 = _metagates.Tensor(Rx(0.6))
    gate2 = _metagates.Tensor(Rx(0.6 + 4 * math.pi))
    assert gate1 == gate2
    assert gate1 != Rx(0.6)
Exemplo n.º 4
0
def test_tensor_get_inverse():
    gate = _metagates.Tensor(Rx(0.6))
    inverse = gate.get_inverse()
    assert isinstance(inverse, _metagates.Tensor)
    assert inverse._gate == Rx(-0.6 + 4 * math.pi)
Exemplo n.º 5
0
def test_tensor_str():
    gate = _metagates.Tensor(Y)
    assert str(gate) == "Tensor(" + str(Y) + ")"
Exemplo n.º 6
0
def test_tensor_init():
    gate = _metagates.Tensor(Y)
    assert gate._gate == Y