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

Feature decouple somd 3 #29

Open
wants to merge 51 commits into
base: feature-decouple-somd-3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8dc92c7
Replace template_config.cfg with Pydantic config
Roy-Haolin-Du Jan 6, 2025
b654a04
test and format for removing run_somd.sh and template_config.cfg
Roy-Haolin-Du Jan 6, 2025
fb7346c
Update engine_config validation, ncycle, runtime and test passed
Roy-Haolin-Du Jan 8, 2025
ec4858f
keep partition as default
Roy-Haolin-Du Jan 8, 2025
abc0b9e
Flexibly handle SOMD configuration files and create an abstract base …
Roy-Haolin-Du Jan 9, 2025
624576e
engine_confi and test
Roy-Haolin-Du Jan 12, 2025
f0730aa
engine_confi and test
Roy-Haolin-Du Jan 12, 2025
8d7b957
only consult somd_config object, not read from files
Roy-Haolin-Du Jan 16, 2025
5c1c09f
consult engine_config to update somd.cfg with the necessary configura…
Roy-Haolin-Du Jan 20, 2025
3c760ef
refactor the lambda array and writing of somd.cfg at diff stages
Roy-Haolin-Du Jan 26, 2025
7b97261
nmoves is a required to be written into somd.cfg
Roy-Haolin-Du Jan 26, 2025
5be62d1
Pass self-set runtime and add simulation timestep attribute
Roy-Haolin-Du Jan 26, 2025
96a6b78
Tweak EngineConfig and refactor system preparation
fjclark Jan 28, 2025
c3abd46
save enginetype between loading and dump, job name at pre-stages
Roy-Haolin-Du Feb 2, 2025
7b8e4c3
pass lambda parameters
Roy-Haolin-Du Feb 3, 2025
d96c928
EnsEnsure first ensemble equilibration restraint is used for all runs
fjclark Feb 3, 2025
f832e86
Fix incorrect stage setter in Leg
fjclark Feb 3, 2025
99be80c
Move system prep config attribute descriptions to the fields
fjclark Feb 3, 2025
a8c315c
Make get_file_name a static method
fjclark Feb 3, 2025
08e0ef6
Make load function ignorant of derived classes
fjclark Feb 3, 2025
5612727
Fix order of decorators
fjclark Feb 3, 2025
76f40d4
Supply lambda values to engine config
fjclark Feb 3, 2025
d7eacda
Import dicts of engine type to config maps in __init__
fjclark Feb 3, 2025
b1d2368
Ensure lambda value information is passed to simulation configs
fjclark Feb 3, 2025
496aeff
check if need restraint at bound/free leg or not
Roy-Haolin-Du Feb 4, 2025
8c0351e
make sure write path for top,crd,mor files in somd.cfg
Roy-Haolin-Du Feb 5, 2025
484cc9d
Only restrain stage need turn on rep-lig on
Roy-Haolin-Du Feb 5, 2025
68fa305
pass timestep and nrg_freq to simulation attribute and correct crd to…
Roy-Haolin-Du Feb 6, 2025
1f63593
ruff check for removing unsed func
Roy-Haolin-Du Feb 6, 2025
a5348f0
add test for update_engine_config_option and modify engine_config tes…
Roy-Haolin-Du Feb 9, 2025
49b4e68
Delete redundant comments
Roy-Haolin-Du Feb 9, 2025
d4f4253
change for importng new SomdSystemPreparationConfig
Roy-Haolin-Du Feb 9, 2025
aa924a6
add test for the update_engine_config_option functio
Roy-Haolin-Du Feb 9, 2025
89490f8
Only bound state need restraints
Roy-Haolin-Du Feb 10, 2025
2b9bf88
self.engine_config.timestep/nrg_freq - make sure the information is s…
Roy-Haolin-Du Feb 10, 2025
19c5b98
import SomdSystemPreparationConfig instead of Systemprepconfig used b…
Roy-Haolin-Du Feb 10, 2025
b34738e
self.engine_config.timestep etc - this means the information is store…
Roy-Haolin-Du Feb 14, 2025
b231b56
Make new test files for testing
Roy-Haolin-Du Feb 14, 2025
1cdf9b3
Make new test files for testing
Roy-Haolin-Du Feb 14, 2025
6a0efab
self.engine_config.timestep etc - this means the information is store…
Roy-Haolin-Du Feb 14, 2025
2a59db6
copy restraint file into stage input and output folders
Roy-Haolin-Du Feb 14, 2025
68b1790
If read lambda from cfg file, make sure pass lambda to lambda_values
Roy-Haolin-Du Feb 14, 2025
d25f6e5
New test files
Roy-Haolin-Du Feb 14, 2025
50f3e1b
Make required stages a property of the sysprep config
fjclark Feb 19, 2025
23243d0
Move enums to configuration
fjclark Feb 19, 2025
7ac160e
In progress... store engine config info in EngineType enum
fjclark Feb 19, 2025
439d203
Merge branch 'feature-decouple-somd-3' of https://github.com/Roy-Haol…
fjclark Feb 19, 2025
d7614f3
changed the EngineType enum,removed the mapping dictionaries
Roy-Haolin-Du Feb 24, 2025
769fd70
making new test data for usage of testing
Roy-Haolin-Du Feb 24, 2025
dbdbaee
making sure somd.cfg is written in the correct place and lambda value…
Roy-Haolin-Du Feb 24, 2025
b353206
New test files for removing mapping, correct somd.cfg writen and lamb…
Roy-Haolin-Du Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 24 additions & 99 deletions a3fe/configuration/_engine_runner_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,43 @@

from __future__ import annotations

import copy as _copy
import logging as _logging
import yaml as _yaml
from abc import ABC, abstractmethod
from pydantic import BaseModel as _BaseModel
from typing import Any as _Any
from typing import Dict as _Dict

from ..run._logging_formatters import _A3feStreamFormatter
class EngineRunnerConfig(_BaseModel):
"""Base class for engine runner configurations."""


class EngineRunnerConfig(ABC):
"""An abstract base class for engine configurations."""

def __init__(
self,
stream_log_level: int = _logging.INFO,
) -> None:
"""
Initialize the engine configuration.

Parameters
----------
stream_log_level : int, Optional, default: logging.INFO
Logging level to use for the steam file handlers.
"""
# Set up logging
self._stream_log_level = stream_log_level
self._set_up_logging()

def _set_up_logging(self) -> None:
"""Set up logging for the configuration."""
# If logger exists, remove it and start again
if hasattr(self, "_logger"):
handlers = self._logger.handlers[:]
for handler in handlers:
self._logger.removeHandler(handler)
handler.close()
del self._logger

# Create a new logger
self._logger = _logging.getLogger(f"{self.__class__.__name__}")
self._logger.propagate = False
self._logger.setLevel(_logging.DEBUG)

# For the stream handler, we want to log at the user-specified level
stream_handler = _logging.StreamHandler()
stream_handler.setFormatter(_A3feStreamFormatter())
stream_handler.setLevel(self._stream_log_level)
self._logger.addHandler(stream_handler)

@abstractmethod
def get_config(self) -> _Dict[str, _Any]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should probably be an abstract method

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if we need this (let's check)

"""
Get the configuration dictionary.

Returns
-------
config : Dict[str, Any]
The configuration dictionary.
"""
pass

def get_file_name(self) -> str:
"""
Get the name of the configuration file.
"""
pass

def dump(self, file_path: str) -> None:
"""
Dump the configuration to a YAML file.
Dump the configuration to a YAML file using `self.model_dump()`.

Parameters
----------
file_path : str
Path to dump the configuration to.
"""
config = self.get_config()
with open(file_path, "w") as f:
_yaml.safe_dump(config, f, default_flow_style=False)
self._logger.info(f"Configuration dumped to {file_path}")
try:
config = self.model_dump()
with open(file_path, "w") as f:
_yaml.safe_dump(config, f)
except Exception as e:
print(f"Error dumping configuration: {e}")
return
print(f"Configuration dumped to {file_path}")

@classmethod
def load(cls, file_path: str) -> EngineRunnerConfig:
Expand All @@ -93,47 +55,10 @@ def load(cls, file_path: str) -> EngineRunnerConfig:
config : EngineRunnerConfig
The loaded configuration.
"""
with open(file_path, "r") as f:
config_dict = _yaml.safe_load(f)
try:
with open(file_path, "r") as f:
config_dict = _yaml.safe_load(f)
except Exception as e:
print(f"Error loading configuration: {e}")
return
return cls(**config_dict)

@abstractmethod
def get_file_name(self) -> str:
"""
Get the name of the configuration file.

Returns
-------
file_name : str
The name of the configuration file.
"""
pass

def __eq__(self, other: object) -> bool:
"""
Check if two configurations are equal.

Parameters
----------
other : object
The other configuration to compare with.

Returns
-------
equal : bool
Whether the configurations are equal.
"""
if not isinstance(other, EngineRunnerConfig):
return NotImplemented
return self.get_config() == other.get_config()

def copy(self) -> EngineRunnerConfig:
"""
Create a deep copy of the configuration.

Returns
-------
config : EngineRunnerConfig
A deep copy of the configuration.
"""
return _copy.deepcopy(self)
Loading