Skip to content

Commit

Permalink
Docstrings for pulses/interpolation.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
lumip committed May 20, 2016
1 parent 76a16e9 commit a7eec93
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 32 deletions.
28 changes: 14 additions & 14 deletions doc/source/qctoolkit.pulses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,110 +9,110 @@ qctoolkit.pulses.branch_pulse_template module

.. automodule:: qctoolkit.pulses.branch_pulse_template
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.conditions module
----------------------------------

.. automodule:: qctoolkit.pulses.conditions
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.function_pulse_template module
-----------------------------------------------

.. automodule:: qctoolkit.pulses.function_pulse_template
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.instructions module
------------------------------------

.. automodule:: qctoolkit.pulses.instructions
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.interpolation module
-------------------------------------

.. automodule:: qctoolkit.pulses.interpolation
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__, __call__

qctoolkit.pulses.loop_pulse_template module
-------------------------------------------

.. automodule:: qctoolkit.pulses.loop_pulse_template
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.parameters module
----------------------------------

.. automodule:: qctoolkit.pulses.parameters
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.plotting module
--------------------------------

.. automodule:: qctoolkit.pulses.plotting
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.pulse_template module
--------------------------------------

.. automodule:: qctoolkit.pulses.pulse_template
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.repetition_pulse_template module
-------------------------------------------------

.. automodule:: qctoolkit.pulses.repetition_pulse_template
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.sequence_pulse_template module
-----------------------------------------------

.. automodule:: qctoolkit.pulses.sequence_pulse_template
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.sequencing module
----------------------------------

.. automodule:: qctoolkit.pulses.sequencing
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

qctoolkit.pulses.table_pulse_template module
--------------------------------------------

.. automodule:: qctoolkit.pulses.table_pulse_template
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__


Module contents
---------------

.. automodule:: qctoolkit.pulses
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__
74 changes: 56 additions & 18 deletions qctoolkit/pulses/interpolation.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
"""This module defines strategies for interpolation between points in a pulse table or similar.
Classes:
InterpolationStrategy: Interface for interpolation strategies.
LinearInterpolationStrategy: Interpolates linearly between two points.
HoldInterpolationStrategy: Interpolates by holding the first point's value.
JumpInterpolationStrategy: Interpolates by holding the second point's value.
"""


from abc import ABCMeta, abstractmethod
import numpy as np
from typing import Any, Tuple
import numpy as np


__all__ = ["InterpolationStrategy", "HoldInterpolationStrategy", "JumpInterpolationStrategy", "LinearInterpolationStrategy"]
__all__ = ["InterpolationStrategy", "HoldInterpolationStrategy",
"JumpInterpolationStrategy", "LinearInterpolationStrategy"]


class InterpolationStrategy(metaclass = ABCMeta):
class InterpolationStrategy(metaclass=ABCMeta):
"""Defines a strategy to interpolate values between two points."""

@abstractmethod
def __call__(self, start: Tuple[float, float], end: Tuple[float, float], times: np.ndarray) -> np.ndarray:
"""Return a sequence of voltage values for the time slot between the previous and the current point (given as (time, value) pairs)
according to the interpolation strategy.
The resulting sequence includes the sample for the time of the current point and start at the sample just after the previous point, i.e.,
is of the form [f(sample(previous_point_time)+1), f(sample(previous_point_time)+2), ... f(sample(current_point_time))].
def __call__(self,
start: Tuple[float, float],
end: Tuple[float, float],
times: np.ndarray) -> np.ndarray:
"""Return a sequence of voltage values for the time slot between the start and the
end point (given as (time, value) pairs) according to the interpolation strategy.
Args:
start ((float, float): The start point of the interpolation as (time, value) pair.
end ((float, float): The end point of the interpolation as (time, value) pair.
times (numpy.ndarray): An array of sample times for which values will be computed. All
values in this array must lie within the boundaries defined by start and end.
Returns:
A numpy.ndarray containing the interpolated values.
"""

@abstractmethod
Expand All @@ -33,9 +53,12 @@ def __hash__(self) -> int:


class LinearInterpolationStrategy(InterpolationStrategy):
"""Interpolates linearly."""
"""An InterpolationStrategy that interpolates linearly between two points."""

def __call__(self, start: Tuple[float, float], end: Tuple[float, float], times: np.ndarray) -> np.ndarray:
def __call__(self,
start: Tuple[float, float],
end: Tuple[float, float],
times: np.ndarray) -> np.ndarray:
m = (end[1] - start[1])/(end[0] - start[0])
interpolator = lambda t: m * (t - start[0]) + start[1]
return interpolator(times)
Expand All @@ -48,11 +71,19 @@ def __repr__(self) -> str:


class HoldInterpolationStrategy(InterpolationStrategy):
"""Holds previous value and jumps to the current value at the last sample."""
"""An InterpolationStrategy that interpolates by holding the value of the start point for the
entire intermediate space."""

def __call__(self, start: Tuple[float, float], end: Tuple[float, float], times: np.ndarray) -> np.ndarray:
def __call__(self,
start: Tuple[float, float],
end: Tuple[float, float],
times: np.ndarray) -> np.ndarray:
if np.any(times < start[0]) or np.any(times > end[0]):
raise ValueError("Time Value for interpolation out of bounds. Must be between {0} and {1}.".format(start[0], end[0]))
raise ValueError(
"Time Value for interpolation out of bounds. Must be between {0} and {1}.".format(
start[0], end[0]
)
)

voltages = np.ones_like(times) * start[1]
return voltages
Expand All @@ -65,12 +96,19 @@ def __repr__(self) -> str:


class JumpInterpolationStrategy(InterpolationStrategy):
"""Jumps to the current value at the first sample and holds."""
# TODO: better name than jump
"""An InterpolationStrategy that interpolates by holding the value of the end point for the
entire intermediate space."""

def __call__(self, start: Tuple[float, float], end: Tuple[float, float], times: np.ndarray) -> np.ndarray:
def __call__(self,
start: Tuple[float, float],
end: Tuple[float, float],
times: np.ndarray) -> np.ndarray:
if np.any(times < start[0]) or np.any(times > end[0]):
raise ValueError("Time Value for interpolation out of bounds. Must be between {0} and {1}.".format(start[0], end[0]))
raise ValueError(
"Time Value for interpolation out of bounds. Must be between {0} and {1}.".format(
start[0], end[0]
)
)

voltages = np.ones_like(times) * end[1]
return voltages
Expand Down

0 comments on commit a7eec93

Please sign in to comment.