Skip to content

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

Open
wants to merge 22 commits into
base: feature-decouple-somd-3
Choose a base branch
from

Conversation

Roy-Haolin-Du
Copy link
Contributor

Description

Fixbug for reading the correct slurm_out_file

EngineType enmu changed and remove the mapping dictionaries.

Correct tmp_files name and make sure lam values enable setting from engine_config

Integration test run locally, won't run on CI

Close #11

Status

All tests and format check passed
Run non-adaptive/adaptive a3fe cases successfully

  • Ready to go

Hi Finlay, hope you are well!
Could you please review @fjclark ?

@Roy-Haolin-Du Roy-Haolin-Du requested a review from fjclark March 5, 2025 11:09
Copy link
Collaborator

@fjclark fjclark left a 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:

@@ -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"
Copy link
Collaborator

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
Copy link
Collaborator

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!

# Check that the calculation is not running
assert not calc.running

# Set the entire simulation time to equilibrated for analysis
Copy link
Collaborator

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

assert not calc.running

# Set the entire simulation time to equilibrated for analysis
for leg in calc.legs:
Copy link
Collaborator

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.

@Roy-Haolin-Du
Copy link
Contributor Author

Description

  • Make the test functions specific to SOMD
  • Make sure the integrations test (non-) adaptive run working
  • Add extensive docs to emphasize updates (pkl changed to yaml), Makefile, pre commit hooks.

All tests and format check passed
Run non-adaptive/adaptive a3fe cases successfully

Hi Finlay, hope you are well!
Could you please review @fjclark ?
No rush! Just take time when you are free.

Thanks so much.

Copy link
Collaborator

@fjclark fjclark left a 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.

entry: bash
args: [-c, "make lint"]

# type check hook
Copy link
Collaborator

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.

entry: bash
args: [-c, "make lint"]

# type check hook
Copy link
Collaborator

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))
Copy link
Collaborator

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
Copy link
Collaborator

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:
Copy link
Collaborator

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)

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"]
Copy link
Collaborator

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

@Roy-Haolin-Du
Copy link
Contributor Author

Description

  • Simplify env setup in Makefile, pre-commit-hooks and CI configuration
  • Refactor calc.setup : sysprep_config setting both bound and free leg
  • Added extensive docs and modified all test files to make sure meeting requirements and working

All tests and format check passed
Run non-adaptive/adaptive a3fe cases successfully

Hi Finlay, hope you are well.
I know you’ve got a busy week with the group meeting and your viva,
Just take a look whenever you have a moment please, no rush!
@fjclark

Thanks so much.

run: |
python -m pip install . --no-deps
micromamba list
export PACKAGE_NAME=a3fe
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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,
Copy link
Collaborator

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]:
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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.
Copy link
Collaborator

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:
Copy link
Collaborator

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

@fjclark
Copy link
Collaborator

fjclark commented May 20, 2025

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:

  • You address the minor changes above, when you have time and if you agree with the comments
  • I'll double-check your changes, then have a quick play around with the new code on ishikawa, when you have some time between calculations - if that's ok (I don't have access to any SLURM workstations at the moment)?
  • Merge and release!
  • You create a zenodo doi for the release including you as an author and stick it on the readme so that people can cite you if they use the code

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!

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