Skip to content

🧹 [code health improvement] Transition csimulator initialization asserts to BNGErrors and BNGLogger - #94

Merged
akutuva21 merged 1 commit into
mainfrom
🧹-transition-assert-to-bngerrors-csimulator-140854119988854650
Apr 13, 2026

Hidden character warning

The head ref may contain hidden characters: "\ud83e\uddf9-transition-assert-to-bngerrors-csimulator-140854119988854650"
Merged

akutuva21 merged 1 commit into
mainfrom
🧹-transition-assert-to-bngerrors-csimulator-140854119988854650

Conversation

@akutuva21

Copy link
Copy Markdown
Owner

What (issue addressed):
The previous implementation of set_species_init and set_parameters in CSimWrapper (bionetgen/simulator/csimulator.py) used simple assert statements to check if the lengths of the passed arrays matched num_spec_init and num_params respectively. These asserts caused hard-to-debug crashes (AssertionError) and were documented with a TODO: Transition to BNGErrors and logging.

Why (maintainability improvement):
Transitioning to explicit checks that raise custom exceptions (BNGSimulatorError) and write precise runtime context to the standardized BNGLogger dramatically improves debugging. The app will now safely catch setup mismatches rather than unexpectedly failing due to standard assertion behaviors which get optimized out when running Python in optimized mode (-O).

Verification (how it was confirmed safe):

  • Introduced the BNGSimulatorError subclass to bionetgen/core/exc.py.
  • Replaced the assert lines with conditional block utilizing self.logger.error and raise BNGSimulatorError in bionetgen/simulator/csimulator.py.
  • Verified logic safety by isolating the unit block tests and using unittest.mock.patch on ctypes.CDLL to ensure the exceptions correctly bubble up with accurate information without side effects.
  • Tested and ran successfully using isolated pytest sessions.

Result:
The PyBioNetGen simulator framework correctly handles argument shape mismatch issues gracefully, fulfilling the explicit TODO and standardizing error handling across the application.


PR created automatically by Jules for task 140854119988854650 started by @akutuva21

Replaced plain `assert` statements used during species and parameter initialization in `csimulator.py` with proper error handling.
The code now explicitly checks lengths, logs detailed mismatch info using `BNGLogger`, and raises a newly introduced `BNGSimulatorError`.

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

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@akutuva21
akutuva21 merged commit 8e09c9a into main Apr 13, 2026
16 of 18 checks passed
@akutuva21
akutuva21 deleted the 🧹-transition-assert-to-bngerrors-csimulator-140854119988854650 branch April 13, 2026 14:34
akutuva21 pushed a commit that referenced this pull request Jun 1, 2026
Unify modelapi export and XML error handling
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