Skip to content

Add CVODES forward sensitivity integration, fix FD bump default, and merge C prototype fixes - #322

Open
akutuva21 wants to merge 90 commits into
RuleWorld:masterfrom
akutuva21:master
Open

Add CVODES forward sensitivity integration, fix FD bump default, and merge C prototype fixes#322
akutuva21 wants to merge 90 commits into
RuleWorld:masterfrom
akutuva21:master

Conversation

@akutuva21

Copy link
Copy Markdown
Member

Summary

  • CVODES forward sensitivity: New method=cvodes for LinearParameterSensitivity action, enabling efficient forward-mode sensitivity analysis via SUNDIALS CVODES
  • Fixed FD bump default: Changed from 5% to 0.1% — the 5% default caused 37-434% errors in finite-difference sensitivity estimates for nonlinear (energy pattern) rate expressions
  • C function prototype fixes: Merged from ruleworld/master — added named parameters, extern "C" wrappers for C++ compat, and main(void) to BLAS/LAPACK declarations throughout bng2/Network3/src/util/mathutils/
  • MacroBNGModel.pm fix: Fixed duplicate error message (second die incorrectly referenced $netfile instead of $rabfile)

akutuva21 and others added 30 commits June 2, 2026 18:54
…NG2.pl

Replaced string eval instantiation (`eval '$model = new '.$options->config->{ModelID};`) with direct class instantiation (`my $model_class = $options->config->{ModelID}; $model = $model_class->new();`) to prevent arbitrary code execution vulnerabilities.

Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com>
1) Rewrote `MacroBNGModel::replaceAll` in C++ to use `reserve` and `append` instead of in-place `replace`.
2) Converted several generator expressions in Python `.join()` calls to list comprehensions.
3) Fixed an invalid argument pass to `dict()` in `bpgMaps.py`.

Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com>
…6731269290707

🛡️ Sentinel: [CRITICAL] Fix command injection vulnerability in MacroBNG2.pl
…2749036622

⚡ Bolt: Optimize string replacement and Python joins
Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com>
…743183774

⚡ Bolt: Optimizing dictionary creation and XML parsing loops
Replaces hardcoded FALSE parameter with actual loopcount()>0 check when calling fcanonise in addedgeg.c, deledgeg.c, and newedgeg.c. Fixes longstanding FIXME (loops) bug.
Three fixes: (1) Writes output headers for SPARSE6/GRAPH6 when filtering in pickg, (2) Changes USERDEF return type from int to long, (3) Renames getline to nauty_getline to avoid POSIX conflict.
Replaces TODO stub with actual implementation that delegates to the sub-expression's toMathMLString method, passing through plist and indent parameters.
Changes the USERDEF function signature from int to long in bng-graph/nauty/nauty24/testg.c. (src/nauty version already handled in #381.)
Replaces list comprehensions inside str.join() with generator expressions to avoid creating intermediate lists.
Replaces list(dict.items()) + list(dict2.items()) with itertools.chain() to avoid creating intermediate lists.
Caches repeated XML element .get() calls in local variables for createMolecule and related functions.
Replaces repeated dict[key] lookups with .get() to reduce dict accesses.
Hoists repeated division by (j+1) outside the inner loop.
Adds 105-line test suite for BnglWriter covering basic serialization, parameter writing, species, rules, and observables.
Adds 42-line test for SpeciesList covering creation with checkIso disabled and pattern graph operations.
Adds tests for checkNegativePopulations covering positive, near-negative, and threshold-negative populations.
Adds CppExportWriter tests. Removes stale CMakeLists.txt.patch.
Replaces TODO stub in CPY file header with working Python ctypes usage example showing how to call the generated .so library.
Removes the  parameter that was being passed through toCVodeString and toMatlabString but never used. The RxnRule RRefs lookup was marked as 'may be obsolete'.
Removes large commented-out code blocks in RxnRule.pm that were explicitly noted as 'Removed by Justin -- being permissive about species syntax'.
- Created `tests/test_ssc_writer.cpp` covering parameter and species formatting.
- Added tests for numeric and non-numeric rate laws with statistical factors.
- Verified removal of local scope directives from rate laws.
- Updated `tests/CMakeLists.txt` to include the new test executable.

Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
akutuva21 and others added 30 commits June 30, 2026 13:11
…p arguments in NFSim dispatcher (#434)

Added numeric and path validations for arguments passed to execvp when invoking NFSim. This prevents a malicious user from providing a crafted unverified path or flags that could result in arbitrary code execution.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Added testing for `updateObservables` in `tests/test_pla_simulator.cpp`.
Added proxy helper functions `setupDummyGroups` and `updateObservables`
to `PlaSimulatorTestProxy` to allow interaction and initialization with
private members and correctly execute the function.
This covers normal observable calculation across standard state elements
and boundary empty state vectors.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
…ngRule

Optimizes regex compilation by making regex objects static const in MacroBNGModel.cpp and PopulationMappingRule.cpp. Also fixes duplicate Catch2 test names and adds bng_parser link to test builds.

Additionally fixes C23 compatibility issues in Network3 mathutils:
- Add proper prototypes for all BLAS/LAPACK extern declarations (ddot, dgemm, dgemv, etc.)
- Fix implicit int in test file main() functions
Fixes command injection vulnerability in Perl scripts by converting 2-argument open() to 3-argument open(). Also fixes C23 compatibility issues in Network3 mathutils (BLAS/LAPACK prototypes, implicit int).
…rtiteGraph parser (#446)

* ⚡ Bolt: [performance improvement] Optimize dictionary lookups in BipartiteGraph parser

💡 What: Replaced generator expressions using `.items()` and linear scans with `dict.keys()` or pre-computed mapping dictionaries in hot paths within `bipartiteGraph.py` and `bpgMaps.py`. Pre-calculated string conversions inside the `NameDictionary` class constructor to enable constant time O(1) lookups in `getIdx` and `getElement` instead of repetitive O(N) operations.

🎯 Why: Generator expressions over dictionary items and repetitive linear scans inside tight loops created significant performance overhead and slowed down the parser during mapping. Lookups based on O(N) operations cause slow parsing when the graph involves numerous patterns and transformations. By reducing the time complexity to O(1) with cached hash map operations, graph generation and transformations become significantly faster.

📊 Impact: Reduces time complexity in graph lookups from O(N) to O(1) for name, index, and element resolution. Mitigates unnecessary generator/iteration allocations in Python, particularly affecting large graph parsings and XML conversions.

🔬 Measurement: Run the test suite or execute `bipartiteGraph.py` on large rulesets and observe the faster conversion rates, as redundant iterations during graph traversal and node/edge parsing have been eliminated.

Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com>

* Delete .jules/bolt.md

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
…id regex dynamically compilation overhead (#447)

💡 What: Optimized `hasModifier` by avoiding string allocations for lowercase conversions, utilizing an inline iterator-based case-insensitive string equality comparison instead. Also avoided regex dynamic compilation inside tight loops in `MacroBNGModel::del_blank` and `MacroBNGModel::pre_species1` by using `std::string` manual parsing instead of `std::regex`.

🎯 Why: In `hasModifier`, string creation and transformation inside loops created unnecessary heap allocation and redundant iteration overhead. Similarly, `std::regex` compilation incurs a heavy performance drain when repeatedly compiling inside loops (such as regex strings in `re_paren` and `re_leading_num`).

📊 Impact: Reduces repetitive string operations in modifier checks and bypasses expensive dynamic regex compilation overhead in parsing.

🔬 Measurement: Compile the C++ binaries and execute tests natively using `make benchmark` and `make test`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
…string operations in parsing loops (#448)

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
…roBNGModel.pm

🚨 Severity: CRITICAL
💡 Vulnerability: 2-argument open() in Perl allows for unintended path manipulations or command injection if inputs are not fully sanitized.
🎯 Impact: Could allow execution of arbitrary shell commands or access to unintended files if filenames contain shell characters.
🔧 Fix: Replaced with safer 3-argument open(), and cleaned up prefix variable strings containing hardcoded modes.
✅ Verification: Verified script syntax and ran the BNG test suite.

Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com>
…ns are out of scope for this sentinel security fix)
What: Converted insecure 2-argument open() calls in Perl scripts to the secure 3-argument format.
Risk: 2-argument open() is vulnerable to file path and command injection.
Solution: Used open(FH, "<", $file) or open(FH, ">", $file) consistently.

Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com>
- Remove .jules/sentinel.md (Jules learning file)
- Remove parse_open*.py, test_eval.pl (discovery scripts, not part of fix)
- Revert MacroBNGModel.pm changes (duplicated by PR #450)
- Revert MacroBNGModel.cpp changes (out-of-scope regex optimization)
Keep BNGAction.pm, Boolean2BNGL.pl, VisOptParse.pm 2-arg open fixes.
…roBNGModel.pm

🛡️ Sentinel: [CRITICAL] Fix Path Injection via 2-Argument Open in MacroBNGModel.pm
🛡️ Sentinel: [HIGH] Fix 2-argument open() vulnerabilities
…insensitive matching

⚡ Bolt: Replace std::transform allocations with zero-allocation case-insensitive matching
…s in compilation loops

⚡ Bolt: [performance improvement] Optimize string case-transformations in compilation loops
…:string finding in MacroBNGModel

⚡ Bolt: [performance improvement] Replace slow regex with manual std::string finding in MacroBNGModel
…s to avoid O(N*M) conversions

What: Pre-compute lowercase model function names outside reaction loop and inline case conversion for rawRateLaw.
Risk: Low
Solution: Avoids expensive std::tolower operations on strings during OdeIntegrator compilation.

Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com>
Pre-compute lowercase model function names outside reaction loop and inline case conversion for rawRateLaw. Avoids expensive std::tolower operations on strings during OdeIntegrator compilation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant