Пример #1
0
    def adjoint(self):
        """Create a tape that is the adjoint of this one.

        Adjointed tapes are the conjugated and transposed version of the
        original tapes. Adjointed ops are equivalent to the inverted operation for unitary
        gates.

        Returns:
            ~.QuantumTape: the adjointed tape
        """
        new_tape = self.copy(copy_operations=True)
        qml.transforms.invisible(new_tape.inv)()

        # the current implementation of the adjoint
        # transform requires that the returned inverted object
        # is automatically queued.
        QuantumTape._lock.acquire()
        try:
            QueuingContext.append(new_tape)
        except Exception as _:
            QuantumTape._lock.release()
            raise
        QuantumTape._lock.release()

        return new_tape
Пример #2
0
 def __enter__(self):
     QuantumTape._lock.acquire()
     try:
         if self.do_queue:
             QueuingContext.append(self)
         return super().__enter__()
     except Exception as _:
         QuantumTape._lock.release()
         raise
Пример #3
0
            def queue(self):
                QueuingContext.append(self, owns=tuple(self.obs))

                for o in self.obs:
                    try:
                        QueuingContext.update_info(o, owner=self)
                    except AttributeError:
                        pass

                return self
Пример #4
0
    def _process_queue(self):
        super()._process_queue()

        for obj, info in self._queue.items():
            QueuingContext.append(obj, **info)

        # remove the operation recorder from the queuing
        # context
        QueuingContext.remove(self)

        new_tape = self.expand(depth=5, stop_at=lambda obj: not isinstance(obj, QuantumTape))
        self.ops = new_tape.operations
        self.obs = new_tape.observables
Пример #5
0
    def adjoint(self):
        """Create a tape that is the adjoint of this one.

        Adjointed tapes are the conjugated and transposed version of the
        original tapes. Adjointed ops are equivalent to the inverted operation for unitary
        gates.

        Returns:
            ~.QuantumTape: the adjointed tape
        """
        new_tape = self.copy(copy_operations=True)

        with qml.tape.stop_recording():
            new_tape.inv()

        # the current implementation of the adjoint
        # transform requires that the returned inverted object
        # is automatically queued.
        with QuantumTape._lock:
            QueuingContext.append(new_tape)

        return new_tape
Пример #6
0
    def test_append_no_context(self):
        """Test that append does not fail when no context is present."""

        QueuingContext.append(qml.PauliZ(0))