Ejemplo n.º 1
0
    def as_bindings(self) -> devices.MixedPrecResistiveDeviceParameter:
        """Return a representation of this instance as a simulator bindings object."""

        mixed_prec_parameter = parameters_to_bindings(self)
        param_device = self.device.as_bindings()

        if not mixed_prec_parameter.set_device_parameter(param_device):
            raise ConfigError("Could not add device parameter")

        return mixed_prec_parameter
Ejemplo n.º 2
0
    def as_bindings(self) -> devices.TransferResistiveDeviceParameter:
        """Return a representation of this instance as a simulator bindings object."""

        if not isinstance(self.unit_cell_devices, list):
            raise ConfigError("unit_cell_devices should be a list of devices")

        n_devices = len(self.unit_cell_devices)

        transfer_parameters = parameters_to_bindings(self)

        param_fast = self.unit_cell_devices[0].as_bindings()
        param_slow = self.unit_cell_devices[1].as_bindings()

        if not transfer_parameters.append_parameter(param_fast):
            raise ConfigError("Could not add unit cell device parameter")

        for _ in range(n_devices - 1):
            if not transfer_parameters.append_parameter(param_slow):
                raise ConfigError("Could not add unit cell device parameter")

        return transfer_parameters
Ejemplo n.º 3
0
    def as_bindings(self) -> devices.VectorResistiveDeviceParameter:
        """Return a representation of this instance as a simulator bindings object."""
        vector_parameters = parameters_to_bindings(self)

        if not isinstance(self.unit_cell_devices, list):
            raise ConfigError("unit_cell_devices should be a list of devices")

        if len(self.unit_cell_devices) > 2:
            self.unit_cell_devices = self.unit_cell_devices[:2]
        elif len(self.unit_cell_devices) == 1:
            self.unit_cell_devices = [self.unit_cell_devices[0],
                                      deepcopy(self.unit_cell_devices[0])]
        elif len(self.unit_cell_devices) != 2:
            raise ConfigError("ReferenceUnitCell expects two unit_cell_devices")

        for param in self.unit_cell_devices:
            device_parameters = param.as_bindings()
            if not vector_parameters.append_parameter(device_parameters):
                raise ConfigError("Could not add unit cell device parameter")

        return vector_parameters
Ejemplo n.º 4
0
def estimate_n_steps(
        rpu_config: Union[SingleRPUConfig, UnitCellRPUConfig]) -> int:
    """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.

    Args:
        rpu_config: 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
            :class:`~aihwkit.simulator.configs.devices.PulseDevice`)

    """
    if not isinstance(rpu_config, SingleRPUConfig):
        return 1000

    device_binding = rpu_config.device.as_bindings()

    if not hasattr(device_binding, 'w_min'):
        raise ConfigError('n_step estimation only for PulsedDevice. ' +
                          'Provide n_step explicitly.')

    weight_granularity = device_binding.calc_weight_granularity()
    w_min = device_binding.w_min
    w_max = device_binding.w_max

    n_steps = int(np.round((w_max - w_min) / weight_granularity))
    return n_steps