Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions qiskit/visualization/pulse/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

Interpolation module for pulse visualization.
"""
from __future__ import annotations
from functools import partial
from typing import Tuple

import numpy as np

Expand All @@ -34,7 +34,7 @@
)
def interp1d(
time: np.ndarray, samples: np.ndarray, nop: int, kind: str = "linear"
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""Deprecated.

Scipy interpolation wrapper.
Expand Down Expand Up @@ -73,7 +73,7 @@ def interp1d(
)
def step_wise(
time: np.ndarray, samples: np.ndarray, nop: int
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
# pylint: disable=unused-argument
"""Deprecated.

Expand All @@ -88,7 +88,7 @@ def step_wise(
samples_ = np.repeat(samples, 2)
re_y_ = np.real(samples_)
im_y_ = np.imag(samples_)
time__ = np.concatenate(([time[0]], np.repeat(time[1:-1], 2), [time[-1]]))
time__: np.ndarray = np.concatenate(([time[0]], np.repeat(time[1:-1], 2), [time[-1]]))
return time__, re_y_, im_y_


Expand Down
92 changes: 46 additions & 46 deletions qiskit/visualization/pulse/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

"""Matplotlib classes for pulse visualization."""

from __future__ import annotations
import collections
from typing import Dict, List, Tuple, Callable, Union, Any
from collections.abc import Callable, Sequence
from typing import Any

import numpy as np

Expand Down Expand Up @@ -65,11 +67,11 @@ def __init__(self, t0: int, tf: int):
t0: starting time of plot
tf: ending time of plot
"""
self.pulses = {}
self.pulses: dict[int, Instruction] = {}
self.t0 = t0
self.tf = tf

self._waveform = None
self._waveform: np.ndarray | None = None
self._framechanges = None
self._setphase = None
self._frequencychanges = None
Expand Down Expand Up @@ -103,55 +105,55 @@ def waveform(self) -> np.ndarray:
return self._waveform[self.t0 : self.tf]

@property
def framechanges(self) -> Dict[int, ShiftPhase]:
def framechanges(self) -> dict[int, ShiftPhase]:
"""Get frame changes."""
if self._framechanges is None:
self._build_waveform()

return self._trim(self._framechanges)

@property
def setphase(self) -> Dict[int, SetPhase]:
def setphase(self) -> dict[int, SetPhase]:
"""Get the SetPhase phase values."""
if self._setphase is None:
self._build_waveform()

return self._trim(self._setphase)

@property
def frequencychanges(self) -> Dict[int, SetFrequency]:
def frequencychanges(self) -> dict[int, SetFrequency]:
"""Get the frequency changes."""
if self._frequencychanges is None:
self._build_waveform()

return self._trim(self._frequencychanges)

@property
def frequencyshift(self) -> Dict[int, ShiftFrequency]:
def frequencyshift(self) -> dict[int, ShiftFrequency]:
"""Set the frequency changes."""
if self._frequencychanges is None:
self._build_waveform()

return self._trim(self._frequencychanges)

@property
def conditionals(self) -> Dict[int, str]:
def conditionals(self) -> dict[int, str]:
"""Get conditionals."""
if self._conditionals is None:
self._build_waveform()

return self._trim(self._conditionals)

@property
def snapshots(self) -> Dict[int, Snapshot]:
def snapshots(self) -> dict[int, Snapshot]:
"""Get snapshots."""
if self._snapshots is None:
self._build_waveform()

return self._trim(self._snapshots)

@property
def labels(self) -> Dict[int, Union[Waveform, Acquire]]:
def labels(self) -> dict[int, Waveform | Acquire]:
"""Get labels."""
if self._labels is None:
self._build_waveform()
Expand All @@ -175,7 +177,7 @@ def is_empty(self) -> bool:

return True

def to_table(self, name: str) -> List[Tuple[int, str, str]]:
def to_table(self, name: str) -> list[tuple[int, str, str]]:
"""Get table contains.

Args:
Expand Down Expand Up @@ -264,7 +266,7 @@ def _build_waveform(self):
self._labels[time] = (tf, command)
self._waveform = wf + pv

def _trim(self, events: Dict[int, Any]) -> Dict[int, Any]:
def _trim(self, events: dict[int, Any]) -> dict[int, Any]:
"""Return events during given `time_range`.

Args:
Expand Down Expand Up @@ -411,14 +413,14 @@ def __init__(self, style: SchedStyle):
def _build_channels(
self,
schedule: ScheduleComponent,
channels: List[Channel],
channels: list[Channel],
t0: int,
tf: int,
show_framechange_channels: bool = True,
) -> Tuple[
Dict[Channel, EventsOutputChannels],
Dict[Channel, EventsOutputChannels],
Dict[Channel, EventsOutputChannels],
) -> tuple[
dict[Channel, EventsOutputChannels],
dict[Channel, EventsOutputChannels],
dict[Channel, EventsOutputChannels],
]:
"""Create event table of each pulse channels in the given schedule.

Expand All @@ -435,12 +437,12 @@ def _build_channels(
snapshot_channels: Snapshots.
"""
# prepare waveform channels
drive_channels = collections.OrderedDict()
measure_channels = collections.OrderedDict()
control_channels = collections.OrderedDict()
acquire_channels = collections.OrderedDict()
snapshot_channels = collections.OrderedDict()
_channels = set()
drive_channels: dict[Channel, EventsOutputChannels] = collections.OrderedDict()
measure_channels: dict[Channel, EventsOutputChannels] = collections.OrderedDict()
control_channels: dict[Channel, EventsOutputChannels] = collections.OrderedDict()
acquire_channels: dict[Channel, EventsOutputChannels] = collections.OrderedDict()
snapshot_channels: dict[Channel, EventsOutputChannels] = collections.OrderedDict()
_channels: set[Channel] = set()
if show_framechange_channels:
_channels.update(schedule.channels)
# take channels that do not only contain framechanges
Expand Down Expand Up @@ -502,12 +504,12 @@ def _build_channels(

@staticmethod
def _scale_channels(
output_channels: Dict[Channel, EventsOutputChannels],
output_channels: dict[Channel, EventsOutputChannels],
scale: float,
channel_scales: Dict[Channel, float] = None,
channels: List[Channel] = None,
channel_scales: dict[Channel, float] = None,
channels: list[Channel] = None,
plot_all: bool = False,
) -> Dict[Channel, float]:
) -> dict[Channel, float]:
"""Count number of channels that contains any instruction to show
and find scale factor of that channel.

Expand All @@ -522,7 +524,7 @@ def _scale_channels(
scale_dict: Scale factor of each channel.
"""
# count numbers of valid waveform
scale_dict = {chan: 0 for chan in output_channels.keys()}
scale_dict: dict[Channel, float] = {chan: 0.0 for chan in output_channels.keys()}
for channel, events in output_channels.items():
v_max = 0
if channels:
Expand Down Expand Up @@ -552,7 +554,7 @@ def _scale_channels(

return scale_dict

def _draw_table(self, figure, channels: Dict[Channel, EventsOutputChannels], dt: float):
def _draw_table(self, figure, channels: dict[Channel, EventsOutputChannels], dt: float):
"""Draw event table if events exist.

Args:
Expand All @@ -561,7 +563,7 @@ def _draw_table(self, figure, channels: Dict[Channel, EventsOutputChannels], dt:
dt: Time interval

Returns:
Tuple[matplotlib.axes.Axes]: Axis objects for table and canvas of pulses.
tuple[matplotlib.axes.Axes]: Axis objects for table and canvas of pulses.
"""
# create table
table_data = []
Expand Down Expand Up @@ -601,7 +603,7 @@ def _draw_table(self, figure, channels: Dict[Channel, EventsOutputChannels], dt:
# pylint: enable=unbalanced-tuple-unpacking
time, ch_name, data_str = data
# item
cell_value[r][3 * c + 0] = "t = %s" % time * dt
cell_value[r][3 * c + 0] = "t = %s" % (time * dt)
cell_value[r][3 * c + 1] = "ch %s" % ch_name
cell_value[r][3 * c + 2] = data_str
table = tb.table(
Expand All @@ -622,7 +624,7 @@ def _draw_table(self, figure, channels: Dict[Channel, EventsOutputChannels], dt:

@staticmethod
def _draw_snapshots(
ax, snapshot_channels: Dict[Channel, EventsOutputChannels], y0: float
ax, snapshot_channels: dict[Channel, EventsOutputChannels], y0: float
) -> None:
"""Draw snapshots to given mpl axis.

Expand All @@ -643,7 +645,7 @@ def _draw_snapshots(
ha="center",
)

def _draw_framechanges(self, ax, fcs: Dict[int, ShiftPhase], y0: float) -> bool:
def _draw_framechanges(self, ax, fcs: dict[int, ShiftPhase], y0: float) -> None:
"""Draw frame change of given channel to given mpl axis.

Args:
Expand All @@ -661,7 +663,7 @@ def _draw_framechanges(self, ax, fcs: Dict[int, ShiftPhase], y0: float) -> bool:
va="center",
)

def _draw_frequency_changes(self, ax, sf: Dict[int, SetFrequency], y0: float) -> bool:
def _draw_frequency_changes(self, ax, sf: dict[int, SetFrequency], y0: float) -> None:
"""Draw set frequency of given channel to given mpl axis.

Args:
Expand Down Expand Up @@ -703,9 +705,7 @@ def _get_channel_color(self, channel: Channel) -> str:
return color

@staticmethod
def _prev_label_at_time(
prev_labels: List[Dict[int, Union[Waveform, Acquire]]], time: int
) -> bool:
def _prev_label_at_time(prev_labels: list[dict[int, Waveform | Acquire]], time: int) -> bool:
"""Check overlap of pulses with previous channels.

Args:
Expand All @@ -724,8 +724,8 @@ def _prev_label_at_time(
def _draw_labels(
self,
ax,
labels: Dict[int, Union[Waveform, Acquire]],
prev_labels: List[Dict[int, Union[Waveform, Acquire]]],
labels: dict[int, Waveform | Acquire],
prev_labels: list[dict[int, Waveform | Acquire]],
y0: float,
) -> None:
"""Draw label of pulse instructions on given mpl axis.
Expand Down Expand Up @@ -763,11 +763,11 @@ def _draw_labels(
def _draw_channels(
self,
ax,
output_channels: Dict[Channel, EventsOutputChannels],
output_channels: dict[Channel, EventsOutputChannels],
interp_method: Callable,
t0: int,
tf: int,
scale_dict: Dict[Channel, float],
scale_dict: dict[Channel, float],
label: bool = False,
framechange: bool = True,
frequencychange: bool = True,
Expand All @@ -789,7 +789,7 @@ def _draw_channels(
Value of final vertical axis of canvas.
"""
y0 = 0
prev_labels = []
prev_labels: list[dict[int, Waveform | Acquire]] = []
for channel, events in output_channels.items():
if events.enable:
# scaling value of this channel
Expand Down Expand Up @@ -882,14 +882,14 @@ def draw(
schedule: ScheduleComponent,
dt: float,
interp_method: Callable,
plot_range: Tuple[float, float],
scale: float = None,
channel_scales: Dict[Channel, float] = None,
plot_range: tuple[float, float],
scale: float | None = None,
channel_scales: dict[Channel, float] | None = None,
plot_all: bool = True,
table: bool = False,
label: bool = False,
framechange: bool = True,
channels: List[Channel] = None,
channels: Sequence[Channel] | None = None,
show_framechange_channels: bool = True,
draw_title: bool = False,
):
Expand Down
24 changes: 12 additions & 12 deletions qiskit/visualization/pulse/qcstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

Style sheets for pulse visualization.
"""
from __future__ import annotations
import warnings

from collections import namedtuple
from typing import Optional, Tuple

import logging

Expand All @@ -32,27 +32,27 @@ class SchedStyle:

def __init__(
self,
figsize: Optional[Tuple[float, float]] = (10.0, 12.0),
figsize: tuple[float, float] | None = (10.0, 12.0),
fig_unit_h_table: float = 0.4,
use_table: bool = True,
table_columns: int = 2,
table_font_size: int = 10,
axis_font_size: int = 18,
label_font_size: int = 10,
icon_font_size: int = 18,
title_font_size: Optional[int] = 25,
title_font_size: int | None = 25,
label_ch_linestyle: str = "--",
label_ch_color: str = "#222222",
label_ch_alpha: float = 0.3,
d_ch_color: ComplexColors = ("#648fff", "#002999"),
u_ch_color: ComplexColors = ("#ffb000", "#994A00"),
m_ch_color: ComplexColors = ("#dc267f", "#760019"),
d_ch_color: ComplexColors = ComplexColors("#648fff", "#002999"),
u_ch_color: ComplexColors = ComplexColors("#ffb000", "#994A00"),
m_ch_color: ComplexColors = ComplexColors("#dc267f", "#760019"),
s_ch_color: str = "#7da781",
s_ch_linestyle: str = "-",
table_color: SchedTableColors = ("#e0e0e0", "#f6f6f6", "#f6f6f6"),
table_color: SchedTableColors = SchedTableColors("#e0e0e0", "#f6f6f6", "#f6f6f6"),
bg_color: str = "#f2f3f4",
num_points: int = 1000,
dpi: Optional[int] = 150,
dpi: int | None = 150,
remove_spacing: bool = True,
max_table_ratio: float = 0.5,
vertical_span: float = 0.2,
Expand Down Expand Up @@ -177,12 +177,12 @@ class PulseStyle:

def __init__(
self,
figsize: Optional[Tuple[float, float]] = (7.0, 5.0),
title_font_size: Optional[int] = 18,
wave_color: ComplexColors = ("#ff0000", "#0000ff"),
figsize: tuple[float, float] | None = (7.0, 5.0),
title_font_size: int | None = 18,
wave_color: ComplexColors = ComplexColors("#ff0000", "#0000ff"),
bg_color: str = "#f2f3f4",
num_points: int = 1000,
dpi: Optional[int] = None,
dpi: int | None = None,
):
"""Create new style sheet.

Expand Down
Loading