GEOPY-1029: Add datetime stamp to simpeg.log and simpeg.out file names#140
GEOPY-1029: Add datetime stamp to simpeg.log and simpeg.out file names#140domfournier merged 3 commits intorelease/GA_4.8from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates SaveLogFilesGeoH5 to support a caller-provided base_name so log/artifact files can be read/written with a configurable prefix instead of hard-coded SimPEG.* filenames.
Changes:
- Add a
base_nameconstructor argument and use it to build.out/.logpaths. - Change output header creation to depend on output file existence rather than
iteration == 0. - Update
save_log()to iterate over extensions and build file paths usingbase_name.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def __init__( | ||
| self, | ||
| h5_object, | ||
| base_name, | ||
| **kwargs, | ||
| ): | ||
| self.base_name = base_name | ||
| super().__init__(h5_object, **kwargs) |
There was a problem hiding this comment.
SaveLogFilesGeoH5 is exported as part of simpeg.directives, but base_name is now a required positional arg. This is a breaking API change for downstream code that instantiates the directive without it. Consider providing a default (e.g., "SimPEG") and/or making it a keyword-only optional parameter to preserve backwards compatibility.
There was a problem hiding this comment.
Na, an update to simpeg comes with it
|
|
||
| for file in [ | ||
| "SimPEG.out", | ||
| "SimPEG.log", | ||
| "ChiFactors.log", | ||
| ".out", | ||
| ".log", | ||
| ".chi", |
There was a problem hiding this comment.
save_log() now looks for a chi-factors file at f"{base_name}.chi", but ScaleMisfitMultipliers writes ChiFactors.log by default (see simpeg/directives/_directives.py:2704). As written, chi-factor logs likely won’t be found/saved. Consider keeping ChiFactors.log, or making the chi-factor filename configurable and aligning both producers/consumers.
| ]: | ||
| filepath = dirpath / file | ||
| filepath = dirpath / f"{self.base_name}{file}" | ||
|
|
||
| if not filepath.is_file(): | ||
| continue | ||
|
|
||
| with open(filepath, "rb") as f: | ||
| raw_file = f.read() | ||
|
|
||
| file_entity = h5_object.get_entity(file)[0] | ||
| file_entity = h5_object.get_entity(f"{self.base_name}{file}")[0] | ||
| if file_entity is None: |
There was a problem hiding this comment.
file_entity = h5_object.get_entity(file)[0] is now using strings like ".out"/".log" as the lookup key, but add_file(filepath) will typically create an entity named after the actual file (e.g., f"{base_name}.out"). This mismatch can prevent updates to existing entities and may repeatedly add new file entities. Use filepath.name (or another consistent identifier) for both get_entity(...) and add_file(...) so the same entity is updated each time.
| self._joint_index = value | ||
|
|
||
|
|
||
| class SaveLogFilesGeoH5(BaseSaveGeoH5): |
There was a problem hiding this comment.
Maybe we could use this PR to add some docstring in there!
GEOPY-1029 - Add datetime stamp to simpeg.log and simpeg.out file names