Skip to main content

About

badcrossbar is a nodal analysis solver for passive crossbar arrays that suffer from line resistance. It solves for currents in all the branches, as well as for voltages at all the nodes of the crossbar. Additionally, it can create diagrams of crossbar arrays colored according to the values of those currents and voltages (or any other variables).

This package was published in SoftwareX as Original Software Publication under the title "badcrossbar: A Python tool for computing and plotting currents and voltages in passive crossbar arrays". To cite, use the following BibTeX entry:

@article{JoksasMehonic2020,
  title     = {{badcrossbar}: A {Python} tool for computing and plotting currents and voltages in passive crossbar arrays},
  author    = {Joksas, Dovydas and Mehonic, Adnan},
  journal   = {SoftwareX},
  volume    = {12},
  pages     = {100617},
  year      = {2020},
  publisher = {Elsevier},
  doi       = {10.1016/j.softx.2020.100617}
}

Background

Conventional crossbars have a structure like the one shown in the image below. Resistive two-terminal devices (depicted here as memristors) are connected to word lines on one side and to bit lines on the other. In the diagram, the crossbar devices are depicted in black, the word lines are depicted as horizontal blue lines and the bit lines as vertical blue lines. Orange circles denote the nodes, i.e. the connections between the devices and the word/bit lines. The segments of word and bit lines between neighbouring nodes are often seen as interconnects between neighbouring devices and can themselves be modelled as resistive elements.

Crossbar structure

In most practical scenarios, we want the resistance of the interconnects to be zero. That is because crossbar arrays containing resistive elements can be used as dot product engines, i.e. systems able to compute vector-matrix products in hardware. Specifically, crossbar arrays with interconnect resistance of zero are able to compute the vector-matrix products of applied voltages (vector) and conductances of the crossbar devices (matrix). In the diagram above, voltages are applied on the left side of the word lines and the vector-matrix product is computed in a form of currents at the bottom of the bit lines.

Installation

pip install badcrossbar

Requirements

  • Python >=3.9
  • cairo >=1.15.10. If pip does not install it automatically, see this.

Usage

Computing

badcrossbar allows to compute branch currents and node voltages for arbitrary values of applied voltages, devices' resistances and interconnect resistances. It assumes that voltages are applied on the left side of the word lines and the outputs (in the bottom of the bit lines) are grounded. One can define either a single resistance value for all interconnects, or two separate values for word and bit line segments using optional parameters r_i_word_line and r_i_bit_line, respectively.

One can compute branch currents and node voltages with the function badcrossbar.compute, as shown in the code below:

import badcrossbar

# Applied voltages in volts.
applied_voltages = [
    [1.5],
    [2.3],
    [1.7],
]

# Device resistances in ohms.
resistances = [
    [345, 903, 755, 257, 646],
    [652, 401, 508, 166, 454],
    [442, 874, 190, 244, 635],
]

# Interconnect resistance in ohms.
r_i = 0.5

# Computing the solution.
solution = badcrossbar.compute(applied_voltages, resistances, r_i)

The returned variable (named solution, in this case) is a named tuple with fields currents and voltages.

Currents

solution.currents is itself a named tuple with fields output, device, word_line and bit_line. The first field represents the output currents, while the rest represent the currents flowing through devices, interconnects along the word lines, and interconnects along the bit lines. All of these branches are depicted in the diagram below:

Crossbar branches

If applied_voltages is an array of shape (m, p) (each column representing a different set of inputs) and resistances is an array of shape (m, n), then:

  • currents.output will be a numpy array of shape (p, n).
  • currents.device, currents.word_line and currents.bit_line will be numpy arrays of shape (m, n) if p = 1, or numpy arrays of shape (m, n, p) if p > 1.

Voltages

solution.voltages is itself a named tuple with fields word_line and bit_line. They represent the voltages at the nodes on the word and bit lines, respectively. These two types of nodes are depicted in the diagram below:

Crossbar nodes

If applied_voltages is an array of shape (m, p) (each column representing a different set of inputs) and resistances is an array of shape (m, n), then voltages.word_line and voltages.bit_line will be numpy arrays of shape (m, n) if p = 1, or numpy arrays of shape (m, n, p) if p > 1.

Example

Suppose we applied four sets of inputs to a crossbar array and wanted to find the current flowing through the device in the first row and fourth column when the third set of inputs was applied. We could print out the current through that device using the following piece of code:

import badcrossbar

# Applied voltages in volts.
applied_voltages = [
    [1.5, 4.1, 2.6, 2.1],
    [2.3, 4.5, 1.1, 0.8],
    [1.7, 4.0, 3.3, 1.1],
]

# Device resistances in ohms.
resistances = [
    [345, 903, 755, 257, 646],
    [652, 401, 508, 166, 454],
    [442, 874, 190, 244, 635],
]

# Interconnect resistance in ohms.
r_i = 0.5

# Computing the solution.
solution = badcrossbar.compute(applied_voltages, resistances, r_i)

# Current that we are interested in (note zero-based indexing).
current = solution.currents.device[0, 3, 2]

print(f"\nCurrent through the device in question is ~{current:.3g} A.")

Output

2021-11-20 09:47:52 (INFO): Initialising simulation.
2021-11-20 09:47:52 (INFO): Started solving for v.
2021-11-20 09:47:52 (INFO): Solved for v.
2021-11-20 09:47:52 (INFO): Extracted node voltages.
2021-11-20 09:47:52 (INFO): Extracted currents from all branches in the crossbar.

Current through the device in question is ~0.00986 A.

More examples can be found in files 1_single_set_of_inputs.py and 2_multiple_sets_of_inputs.py.

Perfectly insulating devices

Devices with infinite resistance can be denoted using resistance value of numpy.inf (or equivalently math.inf).

Plotting

badcrossbar provides badcrossbar.plot module which allows to color crossbar branches and nodes. This is done by functions badcrossbar.plot.branches and badcrossbar.plot.nodes, respectively. Although their primary purpose is for plotting currents and voltages, these functions accept arbitrary arrays and color the branches and nodes, according to the values of these arrays. This functionality is explained in more detail in example 3_different_variables.py.

Currents

The function badcrossbar.plot.branches accepts either individual arrays for crossbar devices, word line branches and bit line branches, or a named tuple containing all currents. If any of the arrays are 3D, they are averaged along the third axis.

The following piece of code computes and plots average branch currents over four sets of applied inputs:

import badcrossbar

# Applied voltages in volts.
applied_voltages = [
    [1.5, 4.1, 2.6, 2.1],
    [2.3, 4.5, 1.1, 0.8],
    [1.7, 4.0, 3.3, 1.1],
]

# Device resistances in ohms.
resistances = [
    [345, 903, 755, 257, 646],
    [652, 401, 508, 166, 454],
    [442, 874, 190, 244, 635],
]

# Interconnect resistance in ohms.
r_i = 0.5

# Computing the solution.
solution = badcrossbar.compute(applied_voltages, resistances, r_i)

# Plotting average branch currents over all four sets of inputs.
# We additionally set a custom filename and label of the color bar.
badcrossbar.plot.branches(
    currents=solution.currents, filename="average-currents", axis_label="Average current (A)"
)

The produced PDF file should contain a diagram similar to the one shown below:

Crossbar currents

Voltages

Similarly, badcrossbar.plot.nodes accepts either individual arrays for nodes on the word and bit lines, or a named tuple containing both sets of voltages. If any of the arrays are 3D, they are averaged along the third axis.

The following piece of code computes and plots average node voltages over four sets of applied inputs:

import badcrossbar

# Applied voltages in volts.
applied_voltages = [
    [1.5, 4.1, 2.6, 2.1],
    [2.3, 4.5, 1.1, 0.8],
    [1.7, 4.0, 3.3, 1.1],
]

# Device resistances in ohms.
resistances = [
    [345, 903, 755, 257, 646],
    [652, 401, 508, 166, 454],
    [442, 874, 190, 244, 635],
]

# Interconnect resistance in ohms.
r_i = 0.5

# Computing the solution.
solution = badcrossbar.compute(applied_voltages, resistances, r_i)

# Plotting average node voltages over all four sets of inputs.
badcrossbar.plot.nodes(
    voltages=solution.voltages, axis_label="Average voltage (V)", filename="average-voltages"
)

The produced PDF file should contain a diagram similar to the one shown below. Because the crossbar array, in this case, is small and the interconnect resistance is small relative to the resistance of the devices, we do not see much variation between voltages of nodes of the same type. Differences become more apparent with larger crossbar arrays, as explored in 2_custom_parameters.py, for example.

Crossbar voltages

Examples of how to plot currents or voltages of only certain parts of the crossbar, or how to take into account only part of the sets of applied voltages can be found in 1_default_parameters.py.

Modifying diagrams

Plotting sub-package produces vector images (as PDF files) that can then be edited in any vector graphics manipulation program. However, it also provides option to modify some of the features of the diagram that might be difficult to change once the image is produced. Example 2_custom_parameters.py explores some of these options, while the complete list of modifiable parameters can be found in function docstrings of badcrossbar.plot module.

Metadata

Release files for badcrossbar 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for badcrossbar 1.1.0
File Size Uploaded Provenance Actions
badcrossbar-1.1.0.tar.gz 41.0 kB Without provenance Details for badcrossbar-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for badcrossbar 1.1.0
File Interpreter ABI Platform Actions
badcrossbar-1.1.0-py3-none-any.whl Python 3 none any Details for badcrossbar-1.1.0-py3-none-any.whl

Total release size: 72.6 kB

Release files / badcrossbar-1.1.0.tar.gz

Download URL badcrossbar-1.1.0.tar.gz
Size 41.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8cfbe90a1f9ab7946cec7544d69a2e3701d0d39fa94be2e9a50de6237d62fdcb
BLAKE2b-256 checksum
How to use checksums
6c4625728b3ffd30c3bb77178afb64afd3351de07a28c1d9dfef37c9109a993a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / badcrossbar-1.1.0-py3-none-any.whl

Download URL badcrossbar-1.1.0-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbf7ebbabf40ac2c7c7eb4ca01243783e1849e49422dda943c489a925aae89f7
BLAKE2b-256 checksum
How to use checksums
81e085d9bcc1b27cbe0d9cd3e1c308c2a264f9db50ef4812c7248285c3cd7d93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Security for badcrossbar 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page