Example #1
0
def test_dirty_qubit_tag():
    tag0 = _dirtyqubit.DirtyQubitTag()
    tag1 = _dirtyqubit.DirtyQubitTag()
    tag2 = ComputeTag()
    assert tag0 == tag1
    assert not tag0 != tag1
    assert not tag0 == tag2
Example #2
0
def test_qubit_placement_tag():
    tag0 = QubitPlacementTag(0)
    tag1 = QubitPlacementTag(0)
    tag2 = QubitPlacementTag(2)
    tag3 = ComputeTag()
    assert tag0 == tag1
    assert not tag0 == tag2
    assert not tag0 == tag3
    assert not tag3 == tag2
Example #3
0
def test_loop_tag():
    tag0 = _loop.LoopTag(10)
    tag1 = _loop.LoopTag(10)
    tag2 = tag0
    tag3 = deepcopy(tag0)
    tag3.num = 9
    other_tag = ComputeTag()
    assert tag0 == tag2
    assert tag0 != tag1
    assert not tag0 == tag3
    assert not tag0 == other_tag
Example #4
0
    def _has_compute_uncompute_tag(self, cmd):
        """
		Return True if command cmd has a compute/uncompute tag.

		Args:
			cmd (Command object): a command object.
		"""
        for t in cmd.tags:
            if t in [UncomputeTag(), ComputeTag()]:
                return True
        return False
Example #5
0
def test_logical_qubit_id_tag():
    tag0 = _logicalqubit.LogicalQubitIDTag(10)
    tag1 = _logicalqubit.LogicalQubitIDTag(1)
    tag2 = tag0
    tag3 = deepcopy(tag0)
    tag3.logical_qubit_id = 9
    other_tag = ComputeTag()
    assert tag0 == tag2
    assert tag0 != tag1
    assert not tag0 == tag3
    assert not tag0 == other_tag
Example #6
0
def test_control_engine_has_compute_tag():
    eng = MainEngine(backend=DummyEngine(), engine_list=[DummyEngine()])
    qubit = eng.allocate_qubit()
    test_cmd0 = Command(eng, H, (qubit,))
    test_cmd1 = Command(eng, H, (qubit,))
    test_cmd2 = Command(eng, H, (qubit,))
    test_cmd0.tags = [DirtyQubitTag(), ComputeTag(), DirtyQubitTag()]
    test_cmd1.tags = [DirtyQubitTag(), UncomputeTag(), DirtyQubitTag()]
    test_cmd2.tags = [DirtyQubitTag()]
    assert _control._has_compute_uncompute_tag(test_cmd0)
    assert _control._has_compute_uncompute_tag(test_cmd1)
    assert not _control._has_compute_uncompute_tag(test_cmd2)
Example #7
0
def test_command_get_inverse(main_engine):
    qubit = main_engine.allocate_qubit()
    ctrl_qubit = main_engine.allocate_qubit()
    cmd = _command.Command(main_engine, Rx(0.5), (qubit,))
    cmd.add_control_qubits(ctrl_qubit)
    cmd.tags = [ComputeTag()]
    inverse_cmd = cmd.get_inverse()
    assert inverse_cmd.gate == Rx(-0.5 + 4 * math.pi)
    assert len(cmd.qubits) == len(inverse_cmd.qubits)
    assert cmd.qubits[0][0].id == inverse_cmd.qubits[0][0].id
    assert id(cmd.qubits[0][0]) != id(inverse_cmd.qubits[0][0])
    assert len(cmd.control_qubits) == len(inverse_cmd.control_qubits)
    assert cmd.control_qubits[0].id == inverse_cmd.control_qubits[0].id
    assert id(cmd.control_qubits[0]) != id(inverse_cmd.control_qubits[0])
    assert cmd.tags == inverse_cmd.tags
    assert id(cmd.tags[0]) != id(inverse_cmd.tags[0])
    assert id(cmd.engine) == id(inverse_cmd.engine)