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)[source]

Compute 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)[source]

Compute 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)[source]

Estimate 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 (Union[aihwkit.simulator.configs.configs.SingleRPUConfig, aihwkit.simulator.configs.configs.UnitCellRPUConfig]) – RPU Configuration to use for plotting

Returns

Guessed number of steps

Raises

ConfigError – If rpu_config.device does not have the w_min attribute (which is only ensured for PulseDevice)

Return type

int

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

Return an analog tile for plotting the response curve.

Parameters
Returns

Instantiated tile.

Return type

aihwkit.simulator.tiles.base.BaseTile

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

Plot 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, use_cuda=False)[source]

Plot 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 (Union[aihwkit.simulator.configs.devices.PulsedDevice, aihwkit.simulator.configs.devices.UnitCell]) – PulsedDevice or UnitCell parameters

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

  • n_steps (Optional[int]) – Number of up/down steps per cycle. If not given, will be tried to be estimated (only for PulsedDevice possible otherwise defaults to 1000 if n_steps=None).

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

  • use_cuda (bool) – Whether to use CUDA for the computation

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, w_init=1.0)[source]

Plot 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,

  • w_init (float) – Initial value of the weights

Return type

None

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

Plot 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)[source]

Plot 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)[source]

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

Parameters
  • rpu_config (Union[aihwkit.simulator.configs.configs.SingleRPUConfig, aihwkit.simulator.configs.configs.UnitCellRPUConfig]) – RPU Configuration to use for plotting

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

  • n_steps (Optional[int]) – Number of up/down steps per cycle. If not given, will be tried to be estimated (only for PulsedDevice possible otherwise defaults to 1000 if n_steps=None).

  • 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.plot_weight_drift(noise_model=None, t_inference_list=None, w_inits=None, n_repeats=25)[source]

Plots the weight drift behavior of a given noise model over time.

Parameters
  • noise_model (Optional[aihwkit.inference.noise.base.BaseNoiseModel]) – Noise model of derived from BaseNoiseModel

  • t_inference_list (Optional[numpy.ndarray]) – Numpy array of times of inference after programming at time 0 (in seconds)

  • w_inits (Optional[numpy.ndarray]) – Numpy array of target weights to program

  • n_repeats (int) – How many repeats to estimate the standard deviation

Return type

None