Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor testing code #41

Merged
merged 17 commits into from
Aug 1, 2024
Merged

Refactor testing code #41

merged 17 commits into from
Aug 1, 2024

Conversation

stefsmeets
Copy link
Contributor

@stefsmeets stefsmeets commented Jul 23, 2024

Hi all, to familiarize myself a bit with the code I had a look at refactoring the test cases. I reduced the number of cycles, so that the tests run about 4 times faster (<2 min instead of 7 min on my pc). I also cleaned and refactored the code, so that the tests now share most of the setup. And the tests now run in a temporary directory, which avoids cluttering the local directory.

Addresses #31

@stefsmeets
Copy link
Contributor Author

This PR is ready, @lsoucasse could you have a look and let me know what you think?

@timlichtenberg timlichtenberg self-requested a review July 24, 2024 14:24
Copy link
Member

@lsoucasse lsoucasse left a comment

Choose a reason for hiding this comment

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

Hi @stefsmeets, thanks for this work.

I really like the shape of the new test scripts that are much more readable. Actually I think the get_spectrum_data and the get_atmosphere_config functions should be part of the Janus module rather than test helpers.

But my main question is about the number of values to be tested. I get your point in reducing the time spent in testing but even if it is the same function that is called, it potentially addresses different coupling convection-radiation regimes. What we could do is testing three orbital values for the instellation test (extremes and middle) and five values in the runaway greenhouse test making sure we capture the flux plateau followed by its increase. Maybe @timlichtenberg or @nichollsh you could share some physics guidelines for this?

@nichollsh
Copy link
Contributor

Capturing the runaway plateau is the key behaviour in the runaway test. Physically, this is checking that the temperature profile sits on the saturation curve for H2O, and therefore covers the physics relating to latent heat and the temperature profile integrator. It also tests SOCRATES longwave calculations.

The instellation test captures the surface energy balance stuff relating to conduction through a solid skin layer above the magma ocean. This also tests the SOCRATES longwave and shortwave calculations.

We can probably restrict this to only a few points, as @lsoucasse suggests, as long as they are well placed (i.e. extrema and the plateau in the runaway case, and high/low instellation in the other case).

@stefsmeets
Copy link
Contributor Author

Can you suggest other ways to reduce the runtime for this test, e.g. by reducing the resolution or otherwise? In my opinion, it is still on the long side, especially if there is a need to test multiple starting values.

I'm mostly interested in ensuring that the code gives the expected output. What in the model or code could change that it would give the expected output at the lower extrema, but not at the higher one? Then we should directly test that instead.

@timlichtenberg
Copy link
Collaborator

The runaway plateau is – unfortunately for this issue – an emergent behaviour that results from a combination of T-P structure, opacity data, and radiative transfer. You need the whole code to achieve these numbers and not a single function can do this. This test is therefore somewhat an integrated test of the overall physical behaviour of the code. Lower resolutions have been previously shown to change the value we aim at here (which is an accepted literature value). So I do not have immediate ideas how to simplify/speed up this test.

@stefsmeets
Copy link
Contributor Author

Okay, it's fairly easy to parametrize the tests now, so I can set it up in a way that new points can be easily added.

It may also be worth having a flag to trigger the full integration test, so it is less disruptive when coding.

@stefsmeets
Copy link
Contributor Author

I have parametrized the tests, so make it easier to add/remove points. I have added the min/max inputs and a middle input to capture the flux plateau. Still slow, but at least a factor 4 improvement over the original code.

Let me know what you think.

Copy link
Member

@lsoucasse lsoucasse 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,
Parametrization gives flexibility in choosing the number of points we want to test.
I suggest we comment the extra reference values instead of deleting them so that we store this information and can easily perform a comprehensive test locally.
For some reason I cannot run the tests on my machine, it gets stuck in the first one and do not move further on. But the tests run fine through the github action.

Co-authored-by: Laurent Soucasse <[email protected]>
@nichollsh nichollsh removed their request for review July 31, 2024 14:30
@stefsmeets stefsmeets merged commit 97ab299 into master Aug 1, 2024
3 checks passed
@stefsmeets stefsmeets deleted the testing branch August 1, 2024 07:03
lsoucasse pushed a commit that referenced this pull request Sep 24, 2024
lsoucasse added a commit that referenced this pull request Sep 24, 2024
* Add fwl_data to .gitignore

* Clean test files

* Move env check to conftest

* Avoid updating class variable

* Clean paths and use tmp directory for output

* Avoid running the same tests twice in a PR

* Refactos greenhous test

* Refactor instellation test

* Clean imports and run code in tmpdir

* Set absolute path for FWL_DATA

* Fix download

* Parametrize tests

* Limit number of tests

* Update tests/test_runaway_greenhouse.py

Co-authored-by: Laurent Soucasse <[email protected]>

* Update tests/test_instellation.py

Co-authored-by: Laurent Soucasse <[email protected]>

---------

Co-authored-by: Laurent Soucasse <[email protected]>
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.

4 participants