-
Notifications
You must be signed in to change notification settings - Fork 12
Feature decouple somd 3 #40
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
base: feature-decouple-somd-3
Are you sure you want to change the base?
Feature decouple somd 3 #40
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much Roy, this looks great! I especially like the thorough tests and what you've done with the integration tests is really nice. Having a general engine_type fixture is a neat solution.
I've left a few small comments to address. A few things left to do before we merge into main are:
- Add extensive docs
- Possibly add a few more tests on e.g. updating config options at the calculation level and checking that the changes propagate down to the simulation level
- Possibly adding a makefile (see https://github.com/fjclark/red/blob/main/Makefile) to simplify installation and add pre-commit hooks (something like https://github.com/fjclark/red/blob/main/.pre-commit-config.yaml) to prevent us forgetting to format before we commit - I always do this. However, this isn't essential, so we can always do this later if you'd prefer.
.github/workflows/CI.yaml
Outdated
@@ -76,7 +76,8 @@ jobs: | |||
# conda setup requires this special shell | |||
shell: bash -l {0} | |||
run: | | |||
pytest -v --cov=a3fe --cov-report=xml --color=yes a3fe/tests/ | |||
# use -m "not integration" to exclude all integration tests | |||
pytest -v --cov=a3fe --cov-report=xml --color=yes a3fe/tests/ -m "not integration" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Clean solution.
|
||
calc.get_optimal_lam_vals(delta_er=2) | ||
|
||
# Check that the old runs have been moved, and that the new lambda values are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please could you check that the new lambda values are different to the old ones? Thanks!
a3fe/tests/test_run_integration.py
Outdated
# Check that the calculation is not running | ||
assert not calc.running | ||
|
||
# Set the entire simulation time to equilibrated for analysis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't set the equilibration time - this should be done automatically when running adaptively. Please check that the equilibration time has successfully been set. Thanks
a3fe/tests/test_run_integration.py
Outdated
assert not calc.running | ||
|
||
# Set the entire simulation time to equilibrated for analysis | ||
for leg in calc.legs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used to have to do this before calc.set_equil
or whatever it is was introduced. Please use this function instead.
…ccess them with a3.SomdConfig etc
… propagate to simulation level
Description
All tests and format check passed Hi Finlay, hope you are well! Thanks so much. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great Roy! Thanks very much for this. I've left a few comments - sorry for being so pedantic. However, this is super close to being merge-able. The updates to the docs look especially great and are super clear.
.pre-commit-config.yaml
Outdated
entry: bash | ||
args: [-c, "make lint"] | ||
|
||
# type check hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overall looks great! However, I'd probably skip the mypy hook for now - at least when I try it, I get hundreds of mypy errors because I didn't start the project with strict type checking and it would be a lot of work to fix it now (although we should probably fix this at some point). The type hints are still useful for understanding the code and for vscode to spot basic mistakes.
.pre-commit-config.yaml
Outdated
entry: bash | ||
args: [-c, "make lint"] | ||
|
||
# type check hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overall looks great! However, I'd probably skip the mypy hook for now - at least when I try it, I get hundreds of mypy errors because I didn't start the project with strict type checking and it would be a lot of work to fix it now (although we should probably fix this at some point). The type hints are still useful for understanding the code and for vscode to spot basic mistakes.
Makefile
Outdated
# For the CI github actions workflow, we skip "make env" and set up the environment manually. In this case, | ||
# it's helpful to to set CONDA_ENV_RUN to be empty. However, for the documentation workflow, we want to override | ||
# this and keep the normal behavior. We override this by setting KEEP_CONDA_ENV_RUN to true in the documentation workflow. | ||
SKIP_CONDA_ENV = $(and $(GITHUB_ACTIONS),$(if $(KEEP_CONDA_ENV_RUN),,true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks great!
I can't quite remember why I added this logic (it's super convoluted) but I think we might be able to simplify here - red
is designed to work on windows/ mac/ linux, which makes the CI more complicated. We only test a3fe on linux because we need slurm, which is linux only. So I think you might be able to remove this complicated logic and just use the make env
etc commands as done e.g. here https://github.com/SimonBoothroyd/absolv/blob/main/.github/workflows/ci.yaml - nice and simple.
$(CONDA_ENV_RUN) ruff format $(PACKAGE_DIR) | ||
$(CONDA_ENV_RUN) ruff check --fix --select I $(PACKAGE_DIR) | ||
|
||
# run tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a test-integration command to run the integration tests? Thanks!
Makefile
Outdated
$(CONDA_ENV_RUN) pytest $(TEST_ARGS) $(PACKAGE_DIR)/tests/ | ||
|
||
# type check | ||
type-check: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, when I run the type checking I get hundreds of errors - maybe best to remove this for now (as fixing would be a bit of a pain right now)
a3fe/tests/__init__.py
Outdated
elif os.environ.get("RUN_SLURM_TESTS") is None: | ||
# Default to not running SLURM tests unless explicitly enabled | ||
RUN_SLURM_TESTS = False | ||
RUN_SLURM_TESTS = os.environ.get("RUN_SLURM_TESTS") not in [None, "False"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, should probably add 0 to this list (as in RUN_SLURM_TESTS=0
should avoid running the tests, and RUN_SLURM_TESTS=1
should run them)! Sorry I forgot
Description
All tests and format check passed Hi Finlay, hope you are well. Thanks so much. |
run: | | ||
python -m pip install . --no-deps | ||
micromamba list | ||
export PACKAGE_NAME=a3fe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just run "make env" here - this seems to be the same as in the makefile. Sorry if I'm missing something!
|
||
# type check hook | ||
- id: mypy | ||
name: Type check python code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to sort out the typing sometime, but definitely one for the future. Apologies for not doing the typing properly from the start!
# Install development tools | ||
$(CONDA_ENV_RUN) pip install -e . | ||
mamba create -y --name $(PACKAGE_NAME) | ||
mamba env update --name $(PACKAGE_NAME) --file devtools/conda-envs/test_env.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is nice and simple
$(error VERSION is not set) | ||
endif | ||
$(CONDA_ENV_RUN) mike deploy --push --update-aliases $(VERSION) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, can the docs now be deployed with mike? That's great if we now have versioned docs - before I did it badly so only the last docs were accessible.
@@ -156,19 +156,15 @@ def calcs(self, value: _Calculation) -> None: | |||
|
|||
def setup( | |||
self, | |||
bound_leg_sysprep_config: _Optional[_BaseSystemPreparationConfig] = None, | |||
free_leg_sysprep_config: _Optional[_BaseSystemPreparationConfig] = None, | |||
sysprep_config: _Optional[_BaseSystemPreparationConfig] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think it's cleaner with just the one config!
@@ -143,7 +141,7 @@ def _validate_input(self) -> None: | |||
# Check backwards, as we care about the most advanced preparation stage | |||
for prep_stage in reversed(_PreparationStage): | |||
files_absent = False | |||
for leg_type in Calculation.required_legs: | |||
for leg_type in [_LegType.FREE, _LegType.BOUND]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we avoid hard-coding this? I'm imagining the case where someone only wants to run e.g. the free leg for some reason. I know that it's hard because we don't yet have the sys prep config, which would contain this information. Some options: 1) supply the sys prep config to init instead of setup 2) Only validate when someone attempts to run setup. What do you think?
``` | ||
```bash | ||
cd your/path/a3fe | ||
RUN_SLURM_TESTS=1 pytest a3fe/tests --run-integration -v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could also mention they can now run "make test-integration" - thanks for adding that!
```bash | ||
RUN_SLURM_TESTS=1 pytest a3fe/tests/test_run_integration.py::TestSlurmIntegration::test_slurm_calculation_setup --run-integration -v | ||
RUN_SLUEM_TESTS=0 pytest a3fe/tests --run-integration -v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo "SLUEM". Also, should --run-integration be removed to avoid confusion? My understanding is that this says "run the integration tests" but RUN_SLURM_TESTS=0 stops them running. In the future, these commands might do different things.
for stage_name in LEGS_WITH_STAGES[leg_name]: | ||
# Check that the check_equil_multiwindow_paired_t.txt file exists | ||
leg_path = os.path.join(calc.base_dir, leg_name) | ||
stage_path = os.path.join(leg_path, stage_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Just commenting on something I've done badly - I've mixed the using strings as paths with os.path.join and using pathlib.Path throughout the code. I think pathlib.Path is nicer and if I wrote from scratch I would only use pathlib.Path. Just mentioning for awareness though - this isn't something we really need to fix.
- Separated system preparation configuration from system preparation and configured SOMD with a3fe.configuration.system_prep_config.SomdSystemPreparationConfig. | ||
|
||
**Migration Guide**: | ||
In previous versions, users needed to configure run_somd.sh and template_config.cfg files to run calculations. | ||
However, with version 0.4.0, these files are no longer needed. Instead, configuration objects (SlurmConfig, SomdConfig, and SomdSystemPreparationConfig) are passed directly to the Calculation object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant, thanks! Maybe add a link to where the docs show an example of doing this?
calc = a3.Calculation(engine_config=engine_config) # Pass to Calculation during creation | ||
|
||
# Or modify parameters after creating the Calculation | ||
calc = a3.Calculation() | ||
calc.engine_config.timestep = 2.0 | ||
# Works if the calculation has not been setup yet | ||
calc.engine_config.timestep = 2.0 # fs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for pointing this out in the docs - this is a super important point. I feel like this may still cause some confusion if people don't read the docs properly. I wonder if we could warn the user if they edit the config directly when the calc has already been setup? Do you have any ideas? Don't worry if not as it's already way better than it used to be! This is fine, just trying to minimise confusion. Might be worth reminding users why this is required - just saying because the configs for the legs etc also need updated
|
||
To see a complete list of available configuration options, run ``somd-freenrg --help-config``. | ||
or inspect the ``a3.SomdConfig`` class in the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could maybe link to the API reference for this class
calc.setup(sysprep_config=cfg) | ||
|
||
You can also modify ``lambda values`` in the config object and the system will only run this defined leg and stage. | ||
For example, to only run the bound restrain stage with specified lambda values, set: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, super clear and helpful
Hi @Roy-Haolin-Du, Thanks very much for the changes, and sorry it took me so long to review - have been super busy recently. This looks great and I've just left a couple of very small and pedantic suggestions. It's pretty much ready to go! I'd suggest this route to release, if good with you:
Does that sound good? Sorry again for the mega delay, and apologies in advance for more slow replies - I've got quite a few holidays and other work on til mid June, but should be less busy then! |
Description
Close #11
Status
All tests and format check passed
Run non-adaptive/adaptive a3fe cases successfully
Hi Finlay, hope you are well!
Could you please review @fjclark ?