Skip to content

Conversation

@NDM14
Copy link

@NDM14 NDM14 commented Jan 21, 2026

Changes:

  • added method is_mapped_state_valid to state class to check whether the capacity array and its index is set when mapc2p is also set.
  • added method is_mapped_solution_valid to check whether every state has a valid mapping at runtime.
  • added test class and test to check whether the updated is_valid method works as intended

The names of the methods are debatable. I tried to I adapt to the existing structure.
Also the ValueError can be exchanged to Warnings or bools. Depending on want you all want.
Raising an ValueError seemed more logical, because the program should break, when the mapping isn't valid, but can go through when no mapping isn't present. That's why I used the boolean there.
To give out logging with a boolean value seems a little bit outdated. I can also introduce errorhandling somewhere, but I'm not sure where it should be. Maybe that should be done when a simulation is created.

NDM14 added 2 commits January 21, 2026 14:38
…the capacity array and its index is set when mapc2p is also set.

- added method is_mapped_solution_valid to check whether every state has a valid mapping at runtime.
@ketch
Copy link
Member

ketch commented Jan 23, 2026

I'd like to see this implemented following the pattern we use everywhere else:

  • each object has a single "is_valid" function
  • All validity tests are done inside that function

This ensures that higher level code doesn't need to know details about the object it is using.

If mapc2p is set, you should check that the capacity index is set to an integer between zero and num_aux - 1, inclusive.

…tern in all objects

- implemented the is_mapped_state_valid method from state class to is_valid so only the is_valid function is used to check for validity
@NDM14
Copy link
Author

NDM14 commented Jan 24, 2026

I hope this is better now. I added the checks to the is_valid method from the state object and removed the new method from the solution object. I also added instructions the the errors to guide the user to the right settings.

@ketch
Copy link
Member

ketch commented Jan 25, 2026

This looks good, modulo one comment I left above. Have you tested this? It would be great to include a test in the PR.

@NDM14
Copy link
Author

NDM14 commented Jan 26, 2026

I would happly add a unittests. The questions is where should I add it to? I can only see regression tests in you test folder

NDM14 added 2 commits January 27, 2026 11:46
- the fixture is taken from the example advection_2d_annulus to get a minial setup to test the validity of the state
@NDM14
Copy link
Author

NDM14 commented Jan 27, 2026

@ketch I added a unit test to the test folder. I added it into a folder called unittest to not interfere with the current test structure. I took the setup from the example mentioned in the issue #614 to get a valid setup to run the tests. I included every possible error in the tests to check whether every error is reached at the right time. I know that the project currently just tests via regression tests or tests the example separately, but I would propose to include this test and maybe expand unit testing to be sure about new code coming into the project. It also could be included in GitHub Actions or pre-hooks.

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.

3 participants