Skip to content

Add tests, fix determinism, and format#1

Open
marict wants to merge 4 commits intomasterfrom
pcurry/to-torch
Open

Add tests, fix determinism, and format#1
marict wants to merge 4 commits intomasterfrom
pcurry/to-torch

Conversation

@marict
Copy link
Collaborator

@marict marict commented Sep 19, 2025

  1. Adds a test suite with simple regression tests on expected data, as well as sanity checks on training behavior
  2. Fixes the tensorflow and numpy seeds for deterministic output
  3. Formats the repo with black and isort

To run tests, from the root of the repo run
"pytest ."

Make sure you have installed all the requirements into your python environment via pip install -r requirements.txt

Testing results:

==================================== test session starts ====================================
platform darwin -- Python 3.9.6, pytest-8.4.0, pluggy-1.6.0
rootdir: /Users/paul_curry/ai2/pinns_project
plugins: anyio-4.9.0, timeout-2.4.0
collected 30 items

main/tests/test_advection_diffusion_regression.py .......                             [ 23%]
main/tests/test_advection_diffusion_training.py ........                              [ 50%]
main/tests/test_lorenz_regression.py .....                                            [ 66%]
main/tests/test_lorenz_training.py .......                                            [ 90%]
main/tests/test_network_initialization.py ...                                         [100%]

==================================== 30 passed in 24.52s ====================================

rminism, regenerated reference data, formatted with black and isort
This commit refactors tests by removing redundant comments and code, updates the order and node parameters in generate_reference_data.py, reduces the number of epochs in training to improve performance, ensures consistent network output, and updates binary reference data for regression tests. It also modifies certain parameters and test setups for improved performance and more efficient testing across regression and training scripts.
… brevity and replaced custom test runner with pytest.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive test suite, implements deterministic behavior for reproducible training, and formats the codebase using black and isort for consistent styling.

  • Adds regression and training tests with 30 test cases for both Lorenz and advection-diffusion systems
  • Fixes TensorFlow and numpy seeds to ensure deterministic neural network outputs and training
  • Formats all Python files using black and isort to improve code readability and maintainability

Reviewed Changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
main/x_grid.py Reformatted nested arrays and improved error handling for missing nodes/weights
main/tests/test_*.py Added comprehensive test suites for network initialization, training behavior, and regression testing
main/requirements.txt Added testing and formatting dependencies (pytest, black, isort)
main/pyproject.toml Added isort configuration to match black formatting
main/newton.py Reformatted code for improved readability
main/neural_net.py Added deterministic seed handling and reformatted network definitions
main/main.py Reformatted imports and function calls for consistency
main/irk_coefficients.py Reformatted nested arrays and improved code structure
main/README.md Added project documentation explaining the PINN algorithm and usage

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Owner

@crewsdw crewsdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I set up my system to run these scripts again, working on your new branch. Interestingly, I'm not seeing the Newton step converge like it used to. Not sure what's going on with that. I need to check against the original write-up.

Interesting stuff with the tests. So the intention is to port this to pytorch? Is it better for this kind of application?

@marict
Copy link
Collaborator Author

marict commented Sep 26, 2025

Looks good to me. I set up my system to run these scripts again, working on your new branch. Interestingly, I'm not seeing the Newton step converge like it used to. Not sure what's going on with that. I need to check against the original write-up.

Interesting stuff with the tests. So the intention is to port this to pytorch? Is it better for this kind of application?

Since the architecture is pretty simple, I don't think it would be worth it to move to pytorch, we can stick with TF.
What script are you running and what output would be the convergence behavior? Are you running this on GPU?

It could be that there is seed sensitivity or the upgrade to the latest TF broke something.

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.

2 participants