Example #1
0
def test_command_init(main_engine):
    qureg0 = Qureg([Qubit(main_engine, 0)])
    qureg1 = Qureg([Qubit(main_engine, 1)])
    qureg2 = Qureg([Qubit(main_engine, 2)])
    # qureg3 = Qureg([Qubit(main_engine, 3)])
    # qureg4 = Qureg([Qubit(main_engine, 4)])
    gate = BasicGate()
    cmd = _command.Command(main_engine, gate, (qureg0, qureg1, qureg2))
    assert cmd.gate == gate
    assert cmd.tags == []
    expected_tuple = (qureg0, qureg1, qureg2)
    for cmd_qureg, expected_qureg in zip(cmd.qubits, expected_tuple):
        assert cmd_qureg[0].id == expected_qureg[0].id
        # Testing that Qubits are now WeakQubitRef objects
        assert type(cmd_qureg[0]) == WeakQubitRef
    assert cmd._engine == main_engine
    # Test that quregs are ordered if gate has interchangeable qubits:
    symmetric_gate = BasicGate()
    symmetric_gate.interchangeable_qubit_indices = [[0, 1]]
    symmetric_cmd = _command.Command(main_engine, symmetric_gate, (qureg2, qureg1, qureg0))
    assert cmd.gate == gate
    assert cmd.tags == []
    expected_ordered_tuple = (qureg1, qureg2, qureg0)
    for cmd_qureg, expected_qureg in zip(symmetric_cmd.qubits, expected_ordered_tuple):
        assert cmd_qureg[0].id == expected_qureg[0].id
    assert symmetric_cmd._engine == main_engine
Example #2
0
def test_command_interchangeable_qubit_indices(main_engine):
    gate = BasicGate()
    gate.interchangeable_qubit_indices = [[0, 4, 5], [1, 2]]
    qubit0 = Qureg([Qubit(main_engine, 0)])
    qubit1 = Qureg([Qubit(main_engine, 1)])
    qubit2 = Qureg([Qubit(main_engine, 2)])
    qubit3 = Qureg([Qubit(main_engine, 3)])
    qubit4 = Qureg([Qubit(main_engine, 4)])
    qubit5 = Qureg([Qubit(main_engine, 5)])
    input_tuple = (qubit4, qubit5, qubit3, qubit2, qubit1, qubit0)
    cmd = _command.Command(main_engine, gate, input_tuple)
    assert (cmd.interchangeable_qubit_indices == [[0, 4, 5], [1, 2]]
            or cmd.interchangeable_qubit_indices == [[1, 2], [0, 4, 5]])
Example #3
0
def test_command_order_qubits(main_engine):
    qubit0 = Qureg([Qubit(main_engine, 0)])
    qubit1 = Qureg([Qubit(main_engine, 1)])
    qubit2 = Qureg([Qubit(main_engine, 2)])
    qubit3 = Qureg([Qubit(main_engine, 3)])
    qubit4 = Qureg([Qubit(main_engine, 4)])
    qubit5 = Qureg([Qubit(main_engine, 5)])
    gate = BasicGate()
    gate.interchangeable_qubit_indices = [[0, 4, 5], [1, 2]]
    input_tuple = (qubit4, qubit5, qubit3, qubit2, qubit1, qubit0)
    expected_tuple = (qubit0, qubit3, qubit5, qubit2, qubit1, qubit4)
    cmd = _command.Command(main_engine, gate, input_tuple)
    for ordered_qubit, expected_qubit in zip(cmd.qubits, expected_tuple):
        assert ordered_qubit[0].id == expected_qubit[0].id