Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 52 additions & 15 deletions examples/28_advanced_irdrop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# (C) Copyright 2020, 2021, 2022, 2023, 2024 IBM. All Rights Reserved.
# (C) Copyright 2020, 2021, 2022, 2023, 2024, 2025 IBM. All Rights Reserved.
#
# Licensed under the MIT license. See LICENSE file in the project root for details.
Copy link
Collaborator

@charlesmackin charlesmackin Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the license lines to the following license statement so that it is consistent with the rest of the AIHWKIT:

# (C) Copyright 2020, 2021, 2022, 2023, 2024, 2025 IBM. All Rights Reserved.
#
# Licensed under the MIT license. See LICENSE file in the project root for details.


Expand Down Expand Up @@ -83,7 +83,7 @@ def rpu_config_modifications(rpu_config: Type[RPUConfigBase]) -> Type[RPUConfigB
rpu_config.forward.ir_drop_v_read = 0.4
rpu_config.forward.ir_drop = 1.0
rpu_config.forward.nm_thres = 1.0
rpu_config.forward.inp_res = 2**10
rpu_config.forward.inp_res = 2**10 - 2
rpu_config.forward.out_bound = -1 # 10 - quite restrictive
rpu_config.forward.out_res = -1
rpu_config.forward.out_noise = 0.0 # prevent bit-wise mode from amplifying noise too much
Expand All @@ -107,9 +107,16 @@ def network_comparison(
Returns: None
"""
plot_model_names_dict = {
"conventional_model_dt_irdrop": r"Conventional \ Mode \ Advanced \ IR \ Drop",
"split_mode_pwm_dt_irdrop": r"Split \ Mode \ Advanced \ IR \ Drop",
"bit_wise_dt_irdrop": r"Bit \ Wise \ Mode \ Advanced \ IR \ Drop",
"default_conventional_model_dt_irdrop":
r"Conventional \ Mode \ Adv.\ IR \ Drop \ Default",
"conventional_model_dt_irdrop_PCMnoise":
r"Conventional \ Mode \ Adv. \ IR \ Drop \ PCM \ Noise",
"conventional_model_dt_irdrop_noADC":
r"Conventional \ Mode \ Advanced \ IR \ Drop \ noADC",
"split_mode_pwm_dt_irdrop":
r"Split \ Mode \ Advanced \ IR \ Drop",
"bit_wise_dt_irdrop":
r"Bit \ Wise \ Mode \ Advanced \ IR \ Drop",
}

# Move the model and tensors to cuda if it is available.
Expand Down Expand Up @@ -211,30 +218,60 @@ def network_comparison(

model_dict = {}

# conventional time-dependent ir drop
rpu_config_conventional_dt_irdrop = rpu_config_modifications(TorchInferenceRPUConfigIRDropT())
model_conventional_dt_irdrop = AnalogLinear(
IN_FEATURES, OUT_FEATURES, bias=False, rpu_config=rpu_config_conventional_dt_irdrop
# default conventional time-dependent ir drop
rpu_config_default_conventional_dt_irdrop = rpu_config_modifications(
TorchInferenceRPUConfigIRDropT()
)
model_dict.update({"conventional_model_dt_irdrop": model_conventional_dt_irdrop})
model_default_conventional_dt_irdrop = AnalogLinear(
IN_FEATURES, OUT_FEATURES, bias=False, rpu_config=rpu_config_default_conventional_dt_irdrop
)
model_dict.update({"default_conventional_model_dt_irdrop":
model_default_conventional_dt_irdrop})

# conventional time-dependent ir drop with input-dependent PCM read noise (flag testing)
rpu_config_conventional_dt_irdrop_PCMnoise = rpu_config_modifications(
TorchInferenceRPUConfigIRDropT())
rpu_config_conventional_dt_irdrop_PCMnoise.forward.apply_xdep_pcm_read_noise = True
rpu_config_conventional_dt_irdrop_PCMnoise.forward.xdep_pcm_read_noise_scale = 1.0
model_conventional_dt_irdrop_PCMnoise = AnalogLinear(
IN_FEATURES, OUT_FEATURES, bias=False, rpu_config=rpu_config_conventional_dt_irdrop_PCMnoise
)
model_dict.update({"conventional_model_dt_irdrop_PCMnoise":
model_conventional_dt_irdrop_PCMnoise})

# conventional time-dependent ir drop without ADC quantization (flag testing)
rpu_config_conventional_dt_irdrop_noADC = rpu_config_modifications(
TorchInferenceRPUConfigIRDropT()
)
rpu_config_conventional_dt_irdrop_noADC.forward.adc_quantization = False
model_conventional_dt_irdrop_noADC = AnalogLinear(
IN_FEATURES, OUT_FEATURES, bias=False, rpu_config=rpu_config_conventional_dt_irdrop_noADC
)
model_dict.update({"conventional_model_dt_irdrop_noADC":
model_conventional_dt_irdrop_noADC})

# split mode pwm time-dependent ir drop
rpu_config_split_mode_dt_irdrop = rpu_config_modifications(TorchInferenceRPUConfigIRDropT())
rpu_config_split_mode_dt_irdrop = rpu_config_modifications(
TorchInferenceRPUConfigIRDropT()
)
rpu_config_split_mode_dt_irdrop.forward.mv_type = AnalogMVType.SPLIT_MODE
rpu_config_split_mode_dt_irdrop.forward.ir_drop_bit_shift = 3
rpu_config_split_mode_dt_irdrop.forward.split_mode_pwm = AnalogMVType.SPLIT_MODE
model_split_mode_dt_irdrop = AnalogLinear(
IN_FEATURES, OUT_FEATURES, bias=False, rpu_config=rpu_config_split_mode_dt_irdrop
)
model_dict.update({"split_mode_pwm_dt_irdrop": model_split_mode_dt_irdrop})
model_dict.update({"split_mode_pwm_dt_irdrop":
model_split_mode_dt_irdrop})

# bit wise time-dependent ir drop
rpu_config_bitwise_dt_irdrop = rpu_config_modifications(TorchInferenceRPUConfigIRDropT())
rpu_config_bitwise_dt_irdrop = rpu_config_modifications(
TorchInferenceRPUConfigIRDropT()
)
rpu_config_bitwise_dt_irdrop.forward.mv_type = AnalogMVType.BIT_WISE
model_bitwise_dt_irdrop = AnalogLinear(
IN_FEATURES, OUT_FEATURES, bias=False, rpu_config=rpu_config_bitwise_dt_irdrop
)
model_dict.update({"bit_wise_dt_irdrop": model_bitwise_dt_irdrop})
model_dict.update({"bit_wise_dt_irdrop":
model_bitwise_dt_irdrop})

# default model
rpu_config_default = rpu_config_modifications(InferenceRPUConfig())
Expand Down
42 changes: 35 additions & 7 deletions src/aihwkit/simulator/parameters/io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# (C) Copyright 2020, 2021, 2022, 2023, 2024 IBM. All Rights Reserved.
# (C) Copyright 2020, 2021, 2022, 2023, 2024, 2025 IBM. All Rights Reserved.
#
# Licensed under the MIT license. See LICENSE file in the project root for details.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the license lines to the following license statement so that it is consistent with the rest of the AIHWKIT:

# (C) Copyright 2020, 2021, 2022, 2023, 2024, 2025 IBM. All Rights Reserved.
#
# Licensed under the MIT license. See LICENSE file in the project root for details.


Expand Down Expand Up @@ -32,11 +32,7 @@ class IOParameters(_PrintableMixin):
"""Short-cut to compute a perfect forward pass.

If ``True``, it assumes an ideal forward pass (e.g. no bound, ADC etc...).
Will disregard all other IOParameters settings in this case.

Note that other noise sources set by
:class:`aihwkit.simulator.parameters.inference.WeightModifierParameter`
and :class:`aihwkit.inference.noise` will still be applied.
Will disregard all other settings in this case.
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Documentation clarity reduced: The original documentation mentioned specific classes (WeightModifierParameter and aihwkit.inference.noise) that would still apply noise sources even when is_perfect=True. This information was removed, which may make it unclear to users that some noise sources could still be active. Consider restoring this helpful context.

Suggested change
Will disregard all other settings in this case.
Will disregard all other settings in this case. Note, however, that some noise sources
(such as those from :class:`WeightModifierParameter` and :mod:`aihwkit.inference.noise`)
may still be active even when ``is_perfect=True``.

Copilot uses AI. Check for mistakes.
"""

mv_type: AnalogMVType = AnalogMVType.ONE_PASS
Expand Down Expand Up @@ -176,7 +172,7 @@ class IOParameters(_PrintableMixin):
analog output (before the ADC), i.e. :math:`\frac{y_i}{1 +
n_i*|y_i|}` where :math:`n_i` is drawn at the instantiation time
by::
out_nonlinearity / out_bound * (1 + out_nonlinearity_std * rand)
out_nonlinearity / out_bound * (1 + out_nonlinearity_std * rand)
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inconsistent spacing in documentation formatting. The indentation is 4 spaces for this line while line 180 has 8 spaces (before the change). This creates an inconsistent code block formatting in the docstring.

Suggested change
out_nonlinearity / out_bound * (1 + out_nonlinearity_std * rand)
out_nonlinearity / out_bound * (1 + out_nonlinearity_std * rand)

Copilot uses AI. Check for mistakes.
"""

out_nonlinearity_std: float = 0.0
Expand Down Expand Up @@ -331,3 +327,35 @@ class IOParametersIRDropT(IOParameters):
PWM/DAC operation increases throughput / energy efficiency
of MVM tile hardware while potentially sacrificing some
analog MVM accuracy."""

apply_xdep_pcm_read_noise: bool = False
"""Sets whether to apply activation (x)-dependent PCM read
noise. This model is implemented within analog_mvm_irdrop_t due
to the inputs needing to be 'prepared' (converted to a ns scale),
which is only accomplished deeper into the mvm implementation (as
opposed to the noise_model parameters within PCMLikeNoiseModel()).
"""

xdep_pcm_read_noise_scale: float = 1.0
"""Scale for the activation (x)-dependent PCM read noise model.
"""

adc_quantization: bool = True
"""Sets whether the ADC Quantization feature is applied; this
implements the 'floor' operation consistent with the behavior a
Current-Controlled Oscillator (CCO) (during current integration)
in the case where a capacitor is not fully charged to achieve a
pulse/oscillation. This feature is particularly important in
capturing the true behavior of SPLIT PWM mode. This feature is
implemented within analog_mvm_irdrop_t taken that it requires
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in documentation: "taken that" should be "given that" for correct grammar.

Suggested change
implemented within analog_mvm_irdrop_t taken that it requires
implemented within analog_mvm_irdrop_t given that it requires

Copilot uses AI. Check for mistakes.
charge units, rather than unit-less quantities.
"""
adc_frequency: float = 6.24
"""Sets the operating frequency of the ADC used for quantization;
quantity provided is in GHz.
"""

ir_drop_integration_sum: bool = False
"""Sets current integration to use summation rather than the default
trapezoidal integation method.
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in docstring: "integation" should be "integration".

Suggested change
trapezoidal integation method.
trapezoidal integration method.

Copilot uses AI. Check for mistakes.
"""
Loading
Loading