brainspy.processors.hardware package#
Module contents#
This package contains the files necessary for handling the hardware processors within the main Processor class. It is composed of a driver instance, which is a connection (for a single, or multiple hardware DNPUs) with one of the following National Instruments measurement devices, which are children of the NationalInstrumentsSetup class (CDAQ-to-NiDAQ or CDAQ-to-CDAQ). The HardwareProcessor module expects that the input data has already been plateaued, and creates (and removes) the ramps, required for not damaging the device. The class manages the creation of slopes for plateaued data before passing the data to the drivers, and it also transforms PyTorch tensors to NumPy arrays, as this is the format that the drivers accept. Once it has read information from the hardware, it passes the data back to PyTorch tensors and it masks out the information in the output corresponding to the points in the ramp. It has been designed in such a way, that it enables to easily develop other hardware drivers if required, and the HardwareProcessor would behave in the exact same way.
Subpackages#
Submodules#
brainspy.processors.hardware.processor module#
File containing the main class for Hardware Processor, which goes inside the Processor class.
- class brainspy.processors.hardware.processor.HardwareProcessor(instrument_configs, slope_length, plateau_length)[source]#
Bases:
ModuleThe HardwareProcessor class helps handling the data before sending it to the drivers of the hardware setups.The input data to the hardware drivers has to be given with a waveform. The waveform is composed of slopes and plateaus.The points in the data that is passed to the HardwareProcessor need to be already represented as plateaus. The HardwareProcessor class creates the slopes to the data, in form of pytorch Tensors, and transforms it to numpy arrays before sending it to the driver.It transforms the obtained readout result back to pytorch Tensors, and removes the created rampings. The input and output Tensors have the same length. The drivers can establish a connection (for a single, or multiple hardware DNPUs) with one of the following National Instruments measurement devices: 1. CDAQ-to-NiDAQ 2. CDAQ-to-CDAQ
Please check https://github.com/BraiNEdarwin/brains-py/wiki/A.-Introduction for more information about hardware setups and how the waveform works.
- close()[source]#
Closes the driver if specified in the driver directory or raise a warning if the driver has not been closed after use.
- forward(x)[source]#
The forward function sends the data through the driver and returns the information from hardware DNPUs. It receives an input pytorch Tensor, where points are represented in plateaus. Then, it generates according rampings to the plateaus to obtain a waveform, translates the result into a numpy array and sends the data to the driver. The resulting response from the DNPU hardware is then converted back to a pytorch tensor, and the rampings, where the results of the rampings are filtered out. The output pytorch Tensor will have the same length as the input pytorch Tensor. The purpose of this class is to compatibility of the the model with Pytorch, and make possible to seamlessly exchange simulations of DNPUs with real hardware. There is an additon of slopes to the data in this model. The data in pytorch is represented in the form of plateaus.
- Parameters:
x (torch.Tensor) – input data in ‘plateau’ format (the forward pass will add/remove the slopes to the data). The expected shape is (batch_size, activation_electrode_no)
- Returns:
output data
- Return type:
torch.Tensor
- forward_numpy(x)[source]#
It enables to use directly the driver, without any transformation to the data. The input should already be in the form of a waveform. The output will be returned in the form of a waveform with the same length as the input. The forward function computes output numpy values from input numpy array. This is done to enable compatibility of the the model which is an nn.Module with numpy
- Parameters:
x (np.array) – input data
- Returns:
output data
- Return type:
np.array
- get_clipping_value()[source]#
Gets the clipping value declared on the hardware processor.
Only exists if processor is for simulation debug. Will be None if processor is hardware.
- Returns:
Clipping value.
- Return type:
torch.Tensor or None
- get_voltage_ranges()[source]#
Gets the voltage ranges declared on the hardware processor.
- Returns:
torch.tensor
- Return type:
voltage_ranges
- is_hardware()[source]#
Checks if the driver is a hardware or not. It will return True if the driver is a NationalInstrumentsSetup instance. It will return False if the HardwareProcessor is initialised with the ‘simulation_debug’ flag in the ‘processor_type’ configuration.
- Returns:
True or False depending on wheather it is a hardware or software driver
- Return type:
bool
- training: bool#