Esempio n. 1
0
    def test_pad_no_delay_on_classical_io_channels(self):
        """Test padding does not apply to classical IO channels."""
        delay = 10
        sched = (
            Delay(delay, MemorySlot(0)).shift(20)
            + Delay(delay, RegisterSlot(0)).shift(10)
            + Delay(delay, SnapshotChannel())
        )

        ref_sched = (
            Delay(delay, MemorySlot(0)).shift(20)
            + Delay(delay, RegisterSlot(0)).shift(10)
            + Delay(delay, SnapshotChannel())
        )

        self.assertEqual(transforms.pad(sched, until=15), ref_sched)
Esempio n. 2
0
    def test_default(self):
        """Test default snapshot channel.
        """
        snapshot_channel = SnapshotChannel()

        self.assertEqual(snapshot_channel.index, 0)
        self.assertEqual(snapshot_channel.name, 's0')
Esempio n. 3
0
    def __init__(self,
                 label: str,
                 snapshot_type: str = 'statevector',
                 name: str = None):
        """Create new snapshot command.

        Args:
            label: Snapshot label which is used to identify the snapshot in the output
            snapshot_type: Type of snapshot, e.g., “state” (take a snapshot of the quantum state)
                The types of snapshots offered are defined in a separate specification
                document for simulators
            name: Snapshot name which defaults to label, but can be different than label
                This parameter is only for display purposes and is not taken into account during
                comparison
        """
        self._type = snapshot_type
        self._channel = SnapshotChannel()
        Command.__init__(self, duration=0)
        self._label = Snapshot.create_name(label)

        if name is not None:
            self._name = Snapshot.create_name(name)
        else:
            self._name = self._label

        Instruction.__init__(self, self, self._channel, name=self.name)
        self._buffer = 0
Esempio n. 4
0
    def test_default(self):
        """Test default snapshot channel."""
        snapshot_channel = SnapshotChannel()

        self.assertEqual(snapshot_channel.index, 0)
        self.assertEqual(snapshot_channel.name, "s0")
        self.assertTrue(isinstance(snapshot_channel, ClassicalIOChannel))
Esempio n. 5
0
    def test_delay_snapshot_channel(self):
        """Test Delay on DriveChannel"""

        snapshot_ch = SnapshotChannel()
        snapshot = Snapshot(label='test')
        # should pass as is an append
        sched = Delay(self.delay_time, snapshot_ch) + snapshot
        self.assertIsInstance(sched, Schedule)
        # should fail due to overlap
        with self.assertRaises(PulseError):
            sched = Delay(self.delay_time, snapshot_ch) | snapshot << 5
            self.assertIsInstance(sched, Schedule)
Esempio n. 6
0
    def __init__(self, name: str, snap_type: str):
        """Create new snapshot command.

        Args:
            name (str): Snapshot name which is used to identify the snapshot in the output.
            snap_type (str): Type of snapshot, e.g., “state” (take a snapshot of the quantum state).
                The types of snapshots offered are defined in a separate specification
                document for simulators.
        """
        self._type = snap_type
        self._channel = SnapshotChannel()
        Command.__init__(self, duration=0, name=name)
        Instruction.__init__(self, self, self._channel, name=name)
Esempio n. 7
0
    def __init__(self, label: str, snap_type: str, start_time: int = 0):
        """Create new snapshot command.

        Args:
            label (str): Snapshot label which is used to identify the snapshot in the output.
            snap_type (str): Type of snapshot, e.g., “state” (take a snapshot of the quantum state).
                The types of snapshots offered are defined in a separate specification
                document for simulators.
            start_time (int, optional): Begin time of snapshot. Defaults to 0.
        """
        PulseCommand.__init__(self, duration=0)
        Instruction.__init__(self, self, start_time, TimeslotCollection([]))
        self._label = label
        self._type = snap_type
        self._channel = SnapshotChannel()
Esempio n. 8
0
    def __init__(self, label: str, snapshot_type: str = 'statevector', name: Optional[str] = None):
        """Create new snapshot.

        Args:
            label: Snapshot label which is used to identify the snapshot in the output.
            snapshot_type: Type of snapshot, e.g., “state” (take a snapshot of the quantum state).
                           The types of snapshots offered are defined by the simulator used.
            name: Snapshot name which defaults to ``label``. This parameter is only for display
                  purposes and is not taken into account during comparison.
        """
        self._label = label
        self._type = snapshot_type
        if name is None:
            name = self.label
        super().__init__(0, SnapshotChannel(), name=name)
Esempio n. 9
0
    def __init__(self,
                 label: str,
                 snapshot_type: str = 'statevector',
                 name: Optional[str] = None):
        """Create new snapshot.

        Args:
            label: Snapshot label which is used to identify the snapshot in the output.
            snapshot_type: Type of snapshot, e.g., “state” (take a snapshot of the quantum state).
                           The types of snapshots offered are defined by the simulator used.
            name: Snapshot name which defaults to ``label``. This parameter is only for display
                  purposes and is not taken into account during comparison.

        Raises:
            PulseError: If snapshot label is invalid.
        """
        if not isinstance(label, str):
            raise PulseError('Snapshot label must be a string.')
        self._channel = SnapshotChannel()
        if name is None:
            name = label
        super().__init__(operands=(label, snapshot_type), name=name)