Skip to content

Fix issues #63 and #65: implement product-side include/exclude filtering and add species observable dirty-flag cache - #85

Merged
jrfaeder merged 1 commit into
RuleWorld:masterfrom
akutuva21:fix/issues-63-65
Jun 5, 2026
Merged

Fix issues #63 and #65: implement product-side include/exclude filtering and add species observable dirty-flag cache#85
jrfaeder merged 1 commit into
RuleWorld:masterfrom
akutuva21:fix/issues-63-65

Conversation

@akutuva21

Copy link
Copy Markdown
Member

Summary

This PR fixes two open issues in NFsim:

Issue #63 — BNGL rule modifier include_products/exclude_products

The include_products/exclude_products modifiers on BNGL reaction rules were previously unimplemented in NFsim, causing a hard abort at XML load time ("not yet enforced in NFsim"). This PR implements full parsing and enforcement of these modifiers, mirroring the existing include_reactants/exclude_reactants implementation.

Changes:

  • Add ProductFilter struct and addExcludeProduct/addIncludeProduct/checkProductFilters methods to TransformationSet
  • Parse ListOfExcludeProducts and ListOfIncludeProducts in NFinput.cpp (replaces hard-error abort)
  • Check product filters in ReactionClass::fire() after getListOfProducts, treating filter violations as null events

Issue #65 — Species observable performance

SpeciesObservable::isObservable(Complex*) was invoked once per (complex, observable) pair per output sample, resulting in O(C x O x M) cost. For models with many histogram-style Species observables, this caused significant slowdowns. This PR adds a dirty-flag cache on Complex objects to avoid redundant recomputation.

Changes:

  • Add _speciesObsCache, _speciesObsCacheSize, _speciesObsDirty to the Complex class
  • Cache is invalidated on all complex modification paths (mergeWithList, updateComplexMembership, molecule state changes, bond changes)
  • System::outputAllObservableCounts and recalculateAllObservables use the cache to avoid re-walking unchanged complexes for every observable

Testing

  • All unit tests pass: util, input, molecule, complex, reactionClass, transformations, templateMolecule, mappingSet
  • Build succeeds with zero errors on GCC 13.2.0 / CMake + Ninja

Fixes #63, Fixes #65

…ing and add species observable dirty-flag cache

Issue #63: Implement include_products/exclude_products BNGL rule modifiers
- Add ProductFilter struct to TransformationSet
- Add addExcludeProduct/addIncludeProduct/checkProductFilters methods
- Parse ListOfExcludeProducts and ListOfIncludeProducts in NFinput.cpp
  (replaces hard-error abort with real parsing and enforcement)
- Check product filters in ReactionClass::fire() after getListOfProducts
  to treat filter violations as null events

Issue #65: Add per-complex species observable dirty-flag cache
- Add _speciesObsCache, _speciesObsCacheSize, _speciesObsDirty to Complex
- Cache is invalidated on complex modifications (mergeWithList,
  updateComplexMembership, molecule state changes, bond changes)
- System::outputAllObservableCounts and recalculateAllObservables use
  the cache to avoid re-walking unchanged complexes for every observable
- Significantly reduces O(C x O x M) cost for models with many
  histogram-style Species observables
@jrfaeder
jrfaeder merged commit 4c3da83 into RuleWorld:master Jun 5, 2026
3 checks passed
@akutuva21
akutuva21 deleted the fix/issues-63-65 branch June 5, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants