-
Notifications
You must be signed in to change notification settings - Fork 5
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
Local additional code #55
Merged
dafyddstephenson
merged 8 commits into
CWorthy-ocean:main
from
dafyddstephenson:local_additional_code
Sep 4, 2024
Merged
Local additional code #55
dafyddstephenson
merged 8 commits into
CWorthy-ocean:main
from
dafyddstephenson:local_additional_code
Sep 4, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Move DataSource out of base/input_dataset.py and into dedicated module base/datasource.py - Expand DataSource to check if location is a directory or local repository - Rename AdditionalCode.source_repo to AdditionalCode.source and change type to DataSource - Make checkout_target an optional attribute to AdditionalCode (default None) - Wrap existing AdditionalCode.get() inside conditional check for 'url','repository' - Rename 'source' and 'source_repo' to 'location' in Case.from_blueprint, Case.persist, and cstar_blueprint_roms_marbl_example.yaml Still todo: - update docstrings - update example notebook
- update AdditionalCode.get() to support copying local files - swap out os for pathlib in additional_code.py and datasource.py - fix typo in input_dataset.py - minor changes to case.py with additional type checking
…st and modify/run with the copy (roms/component.py) - Update pre-commit file to replace remaining instance of cstar_ocean with cstar - Update InputDataset.local_path to point to the symlink created by InputDataset.get() after call (if dataset is local) - Update test_roms_marb_example.py to also include local paths to additional code in 2nd case
…ional code file support - Rename "source" (DataSource) to "location" (str) in __init__ for AdditionalCode and InputDataset. The method uses this arg to create the "source" attribute using source=DataSource(location). This avoids requiring the user to create and supply a DataSource object which itself is just instantiated from a location string. - Rename "local_path" to "local_dir" in AdditionalCode.get to avoid confusion with AdditionalCode.local_path - Add an attribute AdditionalCode.modified_namelists to keep track of edited namelists based on templates - Add logic in AdditionalCode.get() that makes copies of any namelist files with the suffix _TEMPLATE to a file without this suffix and adds it to AdditionalCode.modified_namelists, e.g.: AdditionalCode.namelists = ["roms.in_TEMPLATE",] -> AdditionalCode.modified_namelists = ["roms.in",] - Update ROMSComponent.pre_run() and ROMSComponent.run() to reflect this namelist handling - Minor changes to __str__ in component.py (addressing inconsistencies) - Update cstar_example_notebook.ipynb to reflect all of the above changes
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
TomNicholas
approved these changes
Aug 29, 2024
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'm looking through this and so far it looks good. We should probably chat about #56 at some point though.
…amelists) returns False; update error message in datasource.py to 'file or directory'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
-> This PR branches from #52 , do not merge until merging #52 <-
Closes #31.
Summary
This PR introduces support for local additional code, as well as improving the handling of model namelists that are to be modified by C-Star (the latter changes being necessary to test the former). Local
AdditionalCode
instances should be created using a path to a directory, instead of a remote repository, but the structure of this directory should be the same:Meanwhile, calls to
AdditionalCode.get()
now check whether namelist filenames have_TEMPLATE
as a suffix. If so, a new copy without this suffix is created alongside the template file. The template is tracked withAdditionalCode.namelists
as before, the copy is tracked using a new attributeAdditionalCode.modified_namelists
. This is an improvement on previous handling but not a viable long term solution. I have raised Issue #56 in response.List of changes
Changes directly required for local additional code support:
DataSource
out ofbase/input_dataset.py
and into dedicated modulebase/datasource.py
DataSource
to check if location is a directory or local repositoryAdditionalCode.source_repo
:source_repo
attribute is renamed toAdditionalCode.source
, type changed fromstr
->DataSource
source_repo
argument toAdditionalCode.__init__()
is renamed tolocation
(str
).This location is used by
__init__
to create aDataSource
instance and set theAdditionalCode.source
attribute.source
andsource_repo
tolocation
in:Case.from_blueprint()
Case.persist()
cstar_blueprint_roms_marbl_example.yaml
AdditionalCode.checkout_target
optional (in case source is not a repository)AdditionalCode.get()
. This previously cloned a repository to a temporary location and then moved the files needed by theAdditionalCode
instance. It now does this only ifAdditionalCode.source.location_type
isurl
andAdditionalCode.source.source_type
isrepository
. Iflocation_type
ispath
then the files are simply copied from the provided path.test_roms_marbl_example.py
script now also uses local additional code as well as local input datasets in its second (local) stageRelated changes associated with namelist handling:
These changes were necessary to implement the test described above, as previously the template namelist file was edited in place and so couldn't be re-used by a second case.
AdditionalCode.modified_namelists
to keep track of edited namelists based on templatesAdditionalCode.get()
that makes copies of any namelist files with the suffix_TEMPLATE
to a file without this suffix and adds it toAdditionalCode.modified_namelists
, e.g.:AdditionalCode.namelists = ["roms.in_TEMPLATE",]
->AdditionalCode.modified_namelists = ["roms.in",]
ROMSComponent.pre_run()
andROMSComponent.run()
to reflect this namelist handlingOther/bugfixes:
__str__
s and example notebook to reflect above changes