aihwkit.utils.visualization module

Visualization utilities.

This module includes plotting and visualization utilities for aihwkit. Using this module has extra dependencies that can be installed via the extras mechanism:

pip install aihwkit[visualization]
aihwkit.utils.visualization.compute_pulse_response(analog_tile, direction, use_forward=False)

Computes the pulse response of a given device configuration.

Parameters
  • analog_tile (aihwkit.simulator.tiles.base.BaseTile) – Base tile used for computing the weight traces

  • direction (numpy.ndarray) – numpy vector of directions to sequentially apply (-1 or 1)

  • use_forward (bool) – Whether to use the (noisy) forward pass to read out the weights (otherwise returns exact weight value).

Returns

An numpy array w_trace of dimensions len(direction) x out_size x in_size

Return type

numpy.ndarray

aihwkit.utils.visualization.compute_pulse_statistics(w_nodes, w_trace, direction, up_direction, smoothness=0.5)

Computes the statistics of the step trace from compute_pulse_response().

Parameters
  • w_nodes (numpy.ndarray) – weight range vector to estimate the step histogram

  • w_trace (numpy.ndarray) – weight trace from compute_pulse_response()

  • direction (numpy.ndarray) – direction vector used to generate the weight traces

  • up_direction (bool) – whether and plot to compute the statistics for up or down direction

  • smoothness (float) – value for smoothing the estimation of the statistical step response curves

Returns

Tuple of (dw_mean, dw_std).

Return type

Tuple[numpy.ndarray, numpy.ndarray]

aihwkit.utils.visualization.estimate_n_steps(rpu_config)

Estimates the n_steps.

Note

The estimate of the number of update pulses needed to drive from smallest to largest conductance. The estimation just assumes linear behavior, thus only be a rough estimate for non-linear response curves.

Parameters

rpu_config (aihwkit.simulator.configs.configs.SingleRPUConfig) – RPU Configuration to use for plotting

Returns

Guessed number of steps

Return type

int

aihwkit.utils.visualization.get_tile_for_plotting(rpu_config, n_traces, use_cuda=False, noise_free=False)

Returns an analog tile for plotting the response curve.

Parameters
  • rpu_config (aihwkit.simulator.configs.configs.SingleRPUConfig) – RPU Configuration to use for plotting

  • n_traces (int) – Number of traces to plot

  • use_cuda (bool) – Whether to use the CUDA implementation (if available)

  • noise_free (bool) – Whether to turn-off cycle-to-cycle noises

Returns

Instantiated tile.

Return type

aihwkit.simulator.tiles.base.BaseTile

aihwkit.utils.visualization.plot_device(device, w_noise=0.0, **kwargs)

Plots the step response figure for a given device (preset).

Note

It will use an amount of read weight noise w_noise for reading the weights.

Parameters
Return type

None

aihwkit.utils.visualization.plot_device_compact(device, w_noise=0.0, n_steps=None, n_traces=3)

Plots a compact step response figure for a given device (preset).

Note

It will use an amount of read weight noise w_noise for reading the weights.

Parameters
  • device (aihwkit.simulator.configs.devices.PulsedDevice) – PulsedDevice parameters

  • w_noise (float) – Weight noise standard deviation during read

  • n_steps (int) – Number of steps for up/down cycle

  • n_traces (int) – Number of traces to plot (for device-to-device variation)

Returns

the compact step response figure.

Return type

matplotlib.figure.Figure

aihwkit.utils.visualization.plot_device_symmetry(device, w_noise=0.0, n_pulses=10000, n_traces=3, use_cuda=False)

Plots the response figure for a given device (preset).

It will show the response to alternating up down pulses.

Note

It will use an amount of read weight noise w_noise for reading the weights.

Parameters
  • device (aihwkit.simulator.configs.devices.PulsedDevice) – PulsedDevice parameters

  • n_pulses (int) – total number of pulses

  • w_noise (float) – Weight noise standard deviation during read

  • n_traces (int) – Number of device traces

  • use_cuda (bool) – Whether to use CUDA

Return type

None

aihwkit.utils.visualization.plot_pulse_response(analog_tile, direction, use_forward=False)

Plots the pulse response of a direction vector for each weight of the analog tile.

Parameters
  • analog_tile (aihwkit.simulator.tiles.base.BaseTile) – Base tile used for computing the weight traces

  • direction (numpy.ndarray) – vector of directions to sequentially apply (-1 or 1)

  • use_forward (bool) – Whether to use the (noisy) forward pass to read out the weights (otherwise returns exact weight value).

Returns

from compute_pulse_response()

Return type

w_trace

aihwkit.utils.visualization.plot_pulse_statistics(w_trace, direction, up_direction, num_nodes=100, smoothness=0.5)

Plots the dG-G curve from a given weight trace and direction vector.

Parameters
  • w_trace (numpy.ndarray) – weight trace from compute_pulse_response()

  • direction (numpy.ndarray) – direction vector used to generate w_trace

  • up_direction (bool) – whether and plot to compute the statistics for up or down direction

  • num_nodes (int) – number of nodes for estimation of the step histogram

  • smoothness (float) – value for smoothing the estimation of the statistical step response curves

Returns

A tuple (w_nodes, dw_mean, dw_std) from compute_pulse_statistics()

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

aihwkit.utils.visualization.plot_response_overview(rpu_config, n_loops=5, n_steps=None, n_traces=5, use_cuda=False, smoothness=0.1)

Plots the step response and statistics of a given device configuration.

Parameters
  • rpu_config (aihwkit.simulator.configs.configs.SingleRPUConfig) – RPU Configuration to use for plotting

  • n_loops (int) – How many hyper-cycles (up/down pulse sequences) to plot

  • n_steps (int) – Number of up/down steps per cycle. If not given, will be estimated.

  • n_traces (int) – Number of traces to plot

  • use_cuda (bool) – Whether to use the CUDA implementation (if available)

  • smoothness (float) – value for smoothing the estimation of the statistical step response curves

Return type

None

aihwkit.utils.visualization.zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor

Returns a tensor filled with the scalar value 0, with the shape defined by the variable argument size.

Parameters

size (int...) – a sequence of integers defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple.

Keyword Arguments
  • out (Tensor, optional) – the output tensor.

  • dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_tensor_type()).

  • layout (torch.layout, optional) – the desired layout of returned Tensor. Default: torch.strided.

  • device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

Example:

>>> torch.zeros(2, 3)
tensor([[ 0.,  0.,  0.],
        [ 0.,  0.,  0.]])

>>> torch.zeros(5)
tensor([ 0.,  0.,  0.,  0.,  0.])