Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command/Inst refactor: Acquire (and Kernel, Discriminator) #3935

Merged
merged 28 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b67130e
Make new Acquire instruction and update path to Acquire command to po…
lcapelluto Feb 20, 2020
c284476
Fix some style and continue implementation
lcapelluto Mar 6, 2020
6ac1f2d
Fill in docs and fix tests
lcapelluto Mar 9, 2020
b59df29
Fill in __repr__ and __eq__ as necessary for Kernel, Discriminator, A…
lcapelluto Mar 9, 2020
01a2fe3
Merge remote-tracking branch 'upstream/master' into issue-3750-acquir…
lcapelluto Mar 11, 2020
3b5a6da
Style fixes
lcapelluto Mar 11, 2020
376e513
Fix bug missing inclusion of Acquire type along with AcquireInstruction
lcapelluto Mar 11, 2020
4836eae
Fixup some kernel instantiation in pulse instructions converter
lcapelluto Mar 11, 2020
920c04b
Fixup style
lcapelluto Mar 12, 2020
98f2b2a
Try to fix the docs build
lcapelluto Mar 12, 2020
ebf6577
Merge branch 'master' into issue-3750-acquire-instruction
lcapelluto Mar 12, 2020
dc916e8
Update qiskit/pulse/instructions/acquire.py
lcapelluto Mar 13, 2020
a07534b
Respond to review
lcapelluto Mar 13, 2020
0c617b9
Merge remote-tracking branch 'upstream/master' into issue-3750-acquir…
lcapelluto Mar 13, 2020
907ffdd
Merge branch 'issue-3750-acquire-instruction' of github.com:lcapellut…
lcapelluto Mar 13, 2020
5dfc3d2
Update repr for Kernel and Discriminator to reflect **params. Update …
lcapelluto Mar 16, 2020
e2035bf
Merge branch 'master' into issue-3750-acquire-instruction
lcapelluto Mar 16, 2020
2eda225
style
lcapelluto Mar 16, 2020
73d3ac1
Merge branch 'issue-3750-acquire-instruction' of github.com:lcapellut…
lcapelluto Mar 16, 2020
daaff96
Complete release note
lcapelluto Mar 16, 2020
e75ab92
Merge remote-tracking branch 'upstream/master' into issue-3750-acquir…
lcapelluto Mar 16, 2020
3cfd190
Complete reno note (was missing one line)
lcapelluto Mar 16, 2020
2114fb8
Merge remote-tracking branch 'upstream/master' into issue-3750-acquir…
lcapelluto Mar 18, 2020
9aa874b
discriminator and kernel shouldn't be treated as instruction operands
lcapelluto Mar 18, 2020
1984b8e
Merge branch 'master' into issue-3750-acquire-instruction
mergify[bot] Mar 18, 2020
9c842d7
Add link in releasenote
lcapelluto Mar 18, 2020
ccadf5d
Merge branch 'issue-3750-acquire-instruction' of github.com:lcapellut…
lcapelluto Mar 18, 2020
60b1a23
Update releasenotes/notes/unify-instructions-and-commands-aaa6d8724b8…
lcapelluto Mar 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions qiskit/pulse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@
from .channels import (DriveChannel, MeasureChannel, AcquireChannel,
ControlChannel, RegisterSlot, MemorySlot)
from .cmd_def import CmdDef
from .commands import (Acquire, AcquireInstruction, FrameChange,
PersistentValue, SamplePulse, Snapshot, Kernel,
Discriminator, Delay, ParametricPulse,
from .commands import (AcquireInstruction, FrameChange,
PersistentValue, SamplePulse, Snapshot,
Delay, ParametricPulse,
ParametricInstruction, Gaussian,
GaussianSquare, Drag, ConstantPulse, functional_pulse)
from .configuration import LoConfig, LoRange
from .configuration import LoConfig, LoRange, Kernel, Discriminator
from .exceptions import PulseError
from .instruction_schedule_map import InstructionScheduleMap
from .instructions import Instruction
from .instructions import Acquire, Instruction
from .interfaces import ScheduleComponent
from .schedule import Schedule
100 changes: 13 additions & 87 deletions qiskit/pulse/commands/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,102 +12,22 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
Acquire.
"""
"""Acquire. Deprecated path."""
import warnings

from typing import Optional, Union, List

from qiskit.pulse.exceptions import PulseError
from ..channels import MemorySlot, RegisterSlot, AcquireChannel
from ..instructions import Instruction
from .meas_opts import Discriminator, Kernel
from .command import Command


class Acquire(Command):
"""Acquire."""

ALIAS = 'acquire'
prefix = 'acq'

def __init__(self, duration: int, kernel: Optional[Kernel] = None,
discriminator: Optional[Discriminator] = None,
name: Optional[str] = None):
"""Create new acquire command.

Args:
duration: Duration of acquisition
kernel: The data structures defining the measurement kernels
to be used (from the list of available kernels) and set of parameters
(if applicable) if the measurement level is 1 or 2.
discriminator: Discriminators to be used (from the list of available discriminator)
if the measurement level is 2
name: Name of this command.
from ..exceptions import PulseError

Raises:
PulseError: when invalid discriminator or kernel object is input.
"""
super().__init__(duration=duration)
# pylint: disable=unused-import

self._name = Acquire.create_name(name)

if kernel and not isinstance(kernel, Kernel):
raise PulseError('Invalid kernel object is specified.')
self._kernel = kernel

if discriminator and not isinstance(discriminator, Discriminator):
raise PulseError('Invalid discriminator object is specified.')
self._discriminator = discriminator

@property
def kernel(self):
"""Return kernel settings."""
return self._kernel

@property
def discriminator(self):
"""Return discrimination settings."""
return self._discriminator

def __eq__(self, other: 'Acquire'):
"""Two Acquires are the same if they are of the same type
and have the same kernel and discriminator.

Args:
other: Other Acquire

Returns:
bool: are self and other equal.
"""
return (super().__eq__(other) and
self.kernel == other.kernel and
self.discriminator == other.discriminator)

def __hash__(self):
return hash((super().__hash__(), self.kernel, self.discriminator))

def __repr__(self):
return '%s(duration=%d, kernel=%s, discriminator=%s, name="%s")' % \
(self.__class__.__name__, self.duration, self.name,
self.kernel, self.discriminator)

# pylint: disable=arguments-differ
def to_instruction(self,
qubit: Union[AcquireChannel, List[AcquireChannel]],
mem_slot: Optional[Union[MemorySlot, List[MemorySlot]]] = None,
reg_slots: Optional[Union[RegisterSlot, List[RegisterSlot]]] = None,
mem_slots: Optional[Union[List[MemorySlot]]] = None,
reg_slot: Optional[RegisterSlot] = None,
name: Optional[str] = None) -> 'AcquireInstruction':

return AcquireInstruction(self, qubit, mem_slot=mem_slot, reg_slot=reg_slot,
mem_slots=mem_slots, reg_slots=reg_slots, name=name)
# pylint: enable=arguments-differ
from ..instructions import Acquire
from ..instructions import Instruction


class AcquireInstruction(Instruction):
"""Pulse to acquire measurement result."""
"""Deprecated."""

def __init__(self,
command: Acquire,
Expand All @@ -118,6 +38,12 @@ def __init__(self,
reg_slot: Optional[RegisterSlot] = None,
name: Optional[str] = None):

warnings.warn("The ``AcquireInstruction`` has been deprecated. Please use Acquire with "
"channels instead. For example, AcquireInstruction(Acquire(duration), "
"AcquireChannel(0), MemorySlot(0)) becomes Acquire(duration, "
"AcquireChannel(0), MemorySlot(0)).",
DeprecationWarning)

if isinstance(acquire, list) or isinstance(mem_slot, list) or reg_slots:
warnings.warn('The AcquireInstruction on multiple qubits, multiple '
'memory slots and multiple reg slots is deprecated. The '
Expand Down
74 changes: 3 additions & 71 deletions qiskit/pulse/commands/meas_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,9 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

# pylint: disable=missing-param-doc,useless-super-delegation
"""Measurement options. Deprecated path."""

"""
Measurement options.
"""
# pylint: disable=unused-import

from typing import Optional


class MeasOpts:
"""Measurement options."""

def __init__(self, name: Optional[str] = None, **params):
"""Create new measurement options.

Parameters:
name: Name of measurement option to be used.
"""
self._name = name
self._params = params

@property
def name(self):
"""Return parameter name."""
return self._name

@property
def params(self):
"""Return parameter dict."""
return self._params

def __eq__(self, other: 'MeasOpts'):
"""Two measurement options are the same if they are of the same type
and have the same name and params.

Args:
other: Other Discriminator/Kernel

Returns:
bool: are self and other equal
"""
return (type(self) is type(other) and
self.name == other.name and
self.params == other.params)

def __hash__(self):
return hash((super().__hash__(), self.name, self.params))

def __repr__(self):
return '%s(%s)' % (self.__class__.__name__, self.name)


class Discriminator(MeasOpts):
"""Discriminator."""

def __init__(self, name: Optional[str] = None, **params):
"""Create new discriminator.

Parameters:
name: Name of discriminator to be used
"""
super().__init__(name, **params)


class Kernel(MeasOpts):
"""Kernel."""

def __init__(self, name: Optional[str] = None, **params):
"""Create new kernel.

Parameters:
name: Name of kernel to be used
"""
super().__init__(name, **params)
from qiskit.pulse.configuration import Kernel, Discriminator
40 changes: 40 additions & 0 deletions qiskit/pulse/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,46 @@
from .exceptions import PulseError


class Kernel:
"""Settings for this Kernel, which is responsible for integrating time series (raw) data
into IQ points.
"""

def __init__(self, name: Optional[str] = None, **params):
"""Create new kernel.

Args:
name: Name of kernel to be used
params: Any settings for kerneling.
"""
self.name = name
self.params = params['params']

def __repr__(self):
return "{}({}{})".format(self.__class__.__name__,
"'" + self.name + "', " or "",
self.params)


class Discriminator:
"""Setting for this Discriminator, which is responsible for classifying kerneled IQ points
into 0/1 state results.
"""

def __init__(self, name: Optional[str] = None, **params):
"""Create new discriminator.

Args:
name: Name of discriminator to be used
params: Any settings for discrimination.
"""
self.name = name
self.params = params['params']

def __repr__(self):
return "{}({}{})".format(self.__class__.__name__,
"'" + self.name + "', " or "",
self.params)
class LoRange:
"""Range of LO frequency."""

Expand Down
1 change: 1 addition & 0 deletions qiskit/pulse/instructions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
An instruction can be added to a :py:class:`~qiskit.pulse.Schedule`, which is a
sequence of scheduled Pulse ``Instruction`` s over many channels.
"""
from .acquire import Acquire
from .instruction import Instruction
Loading