Repository navigation
fix(inference): apply g_max reference correctly in pcm and reram noise models - #846
Merged
Merged
Conversation
…e models ReRamWan2022NoiseModel raised an AttributeError when coeff_g_max_reference was passed and, with the default coefficients, scaled the noise against g_max instead of the 40 uS fitting reference. The reference is now stored as prog_coeff_g_max_reference, consistent with the PCM models, and legacy pickles are mapped on load. PCMLikeNoiseModel raised the same AttributeError when prog_coeff and prog_coeff_g_max_reference were given together. Both models now warn when the calibrated reference (25 uS for PCM, 40 uS for ReRAM) is overridden while using the default coefficients, since this can produce noise values that differ from the measured hardware ones. Signed-off-by: Pablo Carmona Gonzalez <pablocarmonagonzalez@gmail.com>
PCMLikeNoiseModel.prog_coeff_g_max_reference is now inferred as float, so assigning the optional g_max in the legacy checkpoint conversion failed mypy. Only copy g_max when it is set, which the noise model constructor already guarantees. Signed-off-by: Pablo Carmona Gonzalez <pablocarmonagonzalez@gmail.com>
…n hermes Follow the HermesPCMNoiseModel approach: with the default coefficients the reference g_max is fixed (25 uS for PCM, 40 uS for ReRAM) and cannot be overridden, while g_max can be set. With custom coefficients the reference can still be given and falls back to g_max. A g_max larger than prog_coeff_g_max_reference now raises a ValueError, since the coefficients are not characterized beyond it, and a smaller g_max issues a warning. The check lives in BaseNoiseModel and runs on the resolved g_max, so it also covers a g_max coming from the conductance converter. ReRamWan2022NoiseModel defaults g_max to 40 uS when neither g_max nor g_converter are given. Signed-off-by: Pablo Carmona Gonzalez <pablocarmonagonzalez@gmail.com>
anu-pub
requested changes
Nov 23, 2026
Signed-off-by: Pablo Carmona Gonzalez <pablocarmonagonzalez@gmail.com>
Signed-off-by: Pablo Carmona Gonzalez <pablocarmonagonzalez@gmail.com>
anu-pub
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues
Fixes #830
Description
Fixes how
PCMLikeNoiseModelandReRamWan2022NoiseModelhandle the g_max reference used to scale programming noise, following the approach ofHermesPCMNoiseModel. Passing a reference no longer raises anAttributeError, and ReRAM noise now scales withg_max. With the default coefficients, the reference is fixed andg_maxis checked against it: a largerg_maxis an error and a smaller one warns.Details
Bugs fixed
ReRamWan2022NoiseModel(coeff_g_max_reference=...)raisedAttributeError: ... no attribute 'coeff_g_max_reference'on the first noise call.prog_coeff_g_max_reference, but_apply_polyreadcoeff_g_max_reference, which was alwaysg_max. The scale factorg_max / referencewas therefore always 1, and the noise did not change withg_max.PCMLikeNoiseModel(prog_coeff=..., prog_coeff_g_max_reference=...)raised the sameAttributeError.Reference and g_max handling (PCM, CustomDriftPCM, ReRAM)
g_maxcan still be set.g_maxif none is given.BaseNoiseModel._check_g_max_referencechecks the finalg_maxagainst the reference. It is shared by all three models.g_max > prog_coeff_g_max_referenceraises aValueError, because the coefficients are not characterized beyond the reference.g_max < prog_coeff_g_max_referenceraises aUserWarning, because the scaled noise may differ from the measured hardware noise.g_maxargument, the check runs afterg_maxis resolved. Ag_maxthat comes fromg_converteris therefore checked too. It raisesValueErrorrather than usingassert, which is removed underpython -Oand matches the existing errors in these constructors.ReRamWan2022NoiseModelnow usesg_max = 40µS when neitherg_maxnorg_converteris given, the same way Hermes sets its default. Without this, the converter's 25 µS default would warn on every default construction.Attribute naming and compatibility
prog_coeff_g_max_reference, the same name the PCM and Hermes models use. The constructor argument is stillcoeff_g_max_reference, so the public API does not change.ReRamWan2022NoiseModel.__setstate__maps the oldcoeff_g_max_referenceattribute when unpickling, so existing checkpoints still load.utils/legacy.pynow copiesg_maxonly when it is set. This fixes a mypy error caused by the PCM reference attribute now being typed asfloat.Behaviour changes
PCMLikeNoiseModelwithg_max > 25, andReRamWan2022NoiseModelwithg_max > 40, now raise aValueErrorwhen the default coefficients are used. All examples and library defaults useg_max=25for PCM and are not affected.ReRamWan2022NoiseModel()now defaults tog_max = 40instead of 25.g_max / 40. Results atg_max = 40are unchanged. Smaller values give proportionally less noise and a warning.Tests
New
NoiseModelGMaxReferenceTestintests/test_inference.py, with 26 cases covering both models:g_maxequal to, larger than, and smaller than the reference, including ag_maxthat comes from the converterAttributeErrorreprosCustomDriftPCMLikeNoiseModelchecksg_maxdoubles the noise