badcrossbar package
Contents
badcrossbar package#
Subpackages#
Submodules#
badcrossbar.check module#
- badcrossbar.check.crossbar_requirements(resistances, applied_voltages, r_i_word_line, r_i_bit_line, **kwargs)[source]#
Checks if crossbar variables satisfy all requirements.
- Parameters
resistances (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]]]) – Resistances of crossbar devices.applied_voltages (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]]]) – Applied voltages.r_i_word_line – Interconnect resistance of the word line segments.
r_i_bit_line – Interconnect resistance of the bit line segments.
- Return type
tuple[ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]],ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]]- Returns
Potentially modified resistances and applied voltages.
- badcrossbar.check.match_shape(**kwargs)[source]#
Checks if arrays have matching dimensions.
- Parameters
**kwargs – Arrays and the dimension along which they should be matched.
- Raises
ValueError – If any of the arrays do not match specified dimensions.
- badcrossbar.check.n_dimensional(array, n_list=[2], name='array')[source]#
Checks that array is n-dimensional.
- Parameters
array (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – Array.n_list (
list[int]) – Possible number of dimensions.name (
str) – Name of the variable.
- Raises
TypeError – If array is not n-dimensional.
- badcrossbar.check.non_empty(array, name='array')[source]#
Checks that array is not empty.
- Parameters
array (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – Array.name (
str) – Name of the array.
- Raises
ValueError – If the array is empty.
- badcrossbar.check.non_infinite_array(array, name='array')[source]#
Checks if all the elements of the array are non-infinite.
- Parameters
array (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – Array.name (
str) – Name of the array.
- Raises
ValueError – If the array contains positive or negative infinities.
- badcrossbar.check.non_negative_array(array, name='array')[source]#
Checks if all the elements of the array are non-negative.
- Parameters
array (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – Array.name (
str) – Name of the array.
- Raises
ValueError – If the array contains negative values.
- badcrossbar.check.non_negative_number(value, name='number')[source]#
Checks if the number is negative.
- Parameters
value (
float) – Number.name (
str) – Name of the number.
- Raises
ValueError – If the number is negative.
- badcrossbar.check.not_none(**kwargs)[source]#
Confirms that at least one of the items is not None.
- Parameters
**kwargs – Items of arbitrary type.
- Return type
dict[str,Any]- Returns
Items that are not None.
- Raises
ValueError – If all of the items are None.
- badcrossbar.check.number(value, name='variable')[source]#
Checks if the variable is a number.
- Parameters
value (
Any) – Variable of arbitrary type.name (
str) – Name of the variable.
- Raises
TypeError – If the variable is not int or float.
- badcrossbar.check.numeric_array(array, name='array')[source]#
Checks that array only contains numbers.
- Parameters
array (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – Array.name (
str) – Name of the array.
- Raises
TypeError – If array contains non-number elements.
- badcrossbar.check.plotting_requirements(device_branch_vals=None, word_line_branch_vals=None, bit_line_branch_vals=None, word_line_node_vals=None, bit_line_node_vals=None, branches=True)[source]#
Checks if arrays containing branch or node values satisfy all requirements.
- Parameters
device_branch_vals (
Optional[ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]]) – Values associated with crossbar devices.word_line_branch_vals (
Optional[ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]]) – Values associated with the interconnect segments along the word lines.bit_line_branch_vals (
Optional[ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]]) – Values associated with the interconnect segments along the bit lines.word_line_node_vals (
Optional[ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]]) – Values associated with the nodes on the word lines.bit_line_node_vals (
Optional[ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]]) – Values associated with the nodes on the bit lines.branches (
bool) – If True, it is assumed that branch values are passed. Otherwise, node values are expected.
- Return type
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]- Returns
Potentially modified branch or nodes values.
- badcrossbar.check.short_circuit(resistances, r_i_word_line, r_i_bit_line)[source]#
Checks if crossbar will be short-circuited.
This refers to a theoretical scenario when there exists a path of zero resistance in a crossbar.
- Parameters
resistances (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – Resistances of crossbar devices.r_i_word_line (
float) – Interconnect resistance of the word line segments.r_i_bit_line (
float) – Interconnect resistance of the bit line segments.
- Raises
ValueError – If any of the devices have zero resistance.
badcrossbar.compute module#
- badcrossbar.compute.compute(applied_voltages, resistances, r_i=None, r_i_word_line=None, r_i_bit_line=None, **kwargs)[source]#
Computes branch currents and node voltages of a crossbar.
- Parameters
applied_voltages (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]]]) – Applied voltages. Voltages must be supplied in an array of shape m x p, where m is the number of word lines and p is the number of examples (sets of voltages applied one by one).resistances (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]]]) – Resistances of crossbar devices. Resistances must be supplied in an array of shape m x n, where n is the number of bit lines.r_i (
Optional[float]) – Interconnect resistance of the word and bit line segments. If None, r_i_word_line and r_i_bit_line are used instead.r_i_word_line (
Optional[float]) – Interconnect resistance of the word line segments.r_i_bit_line (
Optional[float]) – Interconnect resistance of the bit line segments.**node_voltages – If False, None is returned instead of node voltages.
**all_currents – If False, only output currents are returned, while all the other ones are set to None.
- Return type
- Returns
Branch currents and node voltages of the crossbar. Field currents is a named tuple itself with fields output, device, word_line and bit_line and contains output currents, as well as currents flowing through the devices and interconnect segments of the word and bit lines. Field voltages is a named tuple itself with fields word_line and bit_line and contains the voltages at the nodes on the word and bit lines. currents.output is an array of shape p x n, while all the others are arrays of shape m x n if p == 1, or arrays of shape m x n x p if p > 1.
badcrossbar.plot module#
- badcrossbar.plot.branches(device_vals=None, word_line_vals=None, bit_line_vals=None, currents=None, **kwargs)[source]#
Plots a crossbar array and colors its branches according to the values passed. The diagram is saved as a PDF file.
If currents is passed, then it is used to plot the currents in the branches. Otherwise, at least one of {device_vals, word_line_vals, bit_line_vals} has to be passed.
- Parameters
device_vals (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]],None]) – Values associated with crossbar devices.word_line_vals (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]],None]) – Values associated with the interconnect segments along the word lines.bit_line_vals (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]],None]) – Values associated with the interconnect segments along the bit lines.currents (
Optional[Currents]) – Crossbar branch currents. It should have fields device, word_line and bit_line that contain currents flowing through the devices and interconnect segments of the word and bit lines (at least one of them should be not None).**default_color – Normalized RGB values of the nodes and certain types of branches if their values are not provided.
**wire_scaling_factor – Scaling factor for the width of the word and bit lines.
**device_scaling_factor – Scaling factor for the width of the devices. Also scales the nodes.
**node_scaling_factor – Scaling factor for the diameter of the nodes which is combined with device_scaling_factor. For example, if one wanted to only scale the device width by a factor of 2, but keep the node diameter the same, arguments device_scaling_factor = 2 and node_scaling_factor = 1/2 would have to be passed.
**axis_label – Axis label of the color bar.
**low_rgb – Normalized RGB value associated with the lower limit.
**zero_rgb – Normalized RGB value associated with the value of zero.
**high_rgb – Normalized RGB value associated with the upper limit.
**allow_overwrite – If True, can overwrite existing PDF files with the same name.
**filename – Filename, excluding PDF extension.
**device_type – Device type to be drawn. One of {‘memristor’, ‘memristor_2’, ‘resistor_usa’, ‘resistor_europe’}.
**significant_figures – Number of significant figures to use for the limits of the color bar.
**round_crossings – Because the circuit of a crossbar array is non-planar, the 2D diagram of it will have some wire crossings. If round_crossings is False, these crossings will be drawn as straight lines. Otherwise, they will be drawn as semicircles.
**width – Width of the diagram in millimeters.
- badcrossbar.plot.nodes(word_line_vals=None, bit_line_vals=None, voltages=None, **kwargs)[source]#
Plots a crossbar array and colors its nodes according to the values passed. The diagram is saved as a PDF file.
If voltages is passed, then it is used to plot the voltages on the nodes. Otherwise, at least one of {word_line_vals, bit_line_vals} has to be passed.
- Parameters
word_line_vals (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]],None]) – Values associated with the nodes on the word lines.bit_line_vals (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]],None]) – Values associated with the nodes on the bit lines.voltages (
Optional[Voltages]) – Crossbar node voltages. It should have fields word_line and bit_line that contain the potentials at the nodes on the word and bit lines (at least one of them should be not None).**default_color – Normalized RGB values of the branches and certain type of nodes if its values are not provided.
**wire_scaling_factor – Scaling factor for the width of the word and bit lines.
**device_scaling_factor – Scaling factor for the width of the devices.
nodes. (Also scales the) –
**node_scaling_factor – Scaling factor for the diameter of the nodes which is combined with device_scaling_factor. For example, if one wanted to only scale the device width by a factor of 2, but keep the node diameter the same, arguments device_scaling_factor = 2 and node_scaling_factor = 1/2 would have to be passed.
**axis_label – Axis label of the color bar.
**low_rgb – Normalized RGB value associated with the lower limit.
**zero_rgb – Normalized RGB value associated with the value of zero.
**high_rgb – Normalized RGB value associated with the upper limit.
**allow_overwrite – If True, can overwrite existing PDF files with the same name.
**filename – Filename, excluding PDF extension.
**device_type – Device type to be drawn. One of {‘memristor’, ‘memristor_2’, ‘resistor_usa’, ‘resistor_europe’}.
**significant_figures – Number of significant figures to use for the limits of the color bar.
**round_crossings – Because the circuit of a crossbar array is non-planar, the 2D diagram of it will have some wire crossings. If round_crossings is False, these crossings will be drawn as straight lines. Otherwise, they will be drawn as semicircles.
**width – Width of the diagram in millimeters.
badcrossbar.utils module#
- badcrossbar.utils.arrays_shape(*arrays)[source]#
Returns the shape of the first array that is not None.
- Parameters
arrays (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – Arrays.- Returns
Shape.
- badcrossbar.utils.average_if_3D(array)[source]#
If array is 3D, it is averaged along the third axis.
- Parameters
array (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – 2D or 3D array.- Return type
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]- Returns
2D array.
- badcrossbar.utils.distributed_array(flattened_array, model_array)[source]#
Reshapes flattened array.
- Parameters
flattened_array (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – An array whose each column contains a flattened array.model_array (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – An array whose shape is used for reshaping.
- Return type
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]- Returns
Array or a list of arrays in specified shape.
- badcrossbar.utils.load_pickle(path, sanitize=True)[source]#
Loads pickle file.
- Parameters
path (
str) – Path to the pickle file, including extension.sanitize (
bool) – If True, sanitizes the filename by removing illegal characters and making the path compatible with the operating system.
- Returns
Extracted contents.
- badcrossbar.utils.save_pickle(variable, path, allow_overwrite=False, sanitize=True)[source]#
Saves variable to a pickle file.
- Parameters
variable – Variable to be saved.
path (
str) – Path to the pickle file, excluding extension.allow_overwrite (
bool) – If False, will not check for existing files with the same name and will overwrite if such files exist.sanitize (
bool) – If True, sanitizes the filename by removing illegal characters and making the path compatible with the operating system.
- badcrossbar.utils.squeeze_third_axis(array)[source]#
Removes third axis of ndarray if it has shape of 1.
- Parameters
array (
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]) – 3D array.- Return type
ndarray[Any,dtype[TypeVar(ScalarType, bound=generic, covariant=True)]]- Returns
2D or 3D array.
- badcrossbar.utils.unique_path(path, extension='pdf', sanitize=True)[source]#
Append a number to the path, if it is not unique.
- Parameters
path (
str) – Path of the filename without the extension.extension (
str) – File extension.sanitize (
bool) – If True, sanitizes the filename by removing illegal characters and making the path compatible with the operating system.
- Return type
str- Returns
Unique path.