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

flepimop patch Abilities And Documentation #423

Merged
merged 13 commits into from
Dec 11, 2024

Conversation

TimothyWillard
Copy link
Contributor

Describe your changes.

This pull request is in response to #375 (comment).

Does this pull request make any user interface changes? If so please describe.

The user interface changes are...

Those are reflected in updates to the documentation in ...

Tag relevant team members.

@saraloo @pearsonca

@TimothyWillard TimothyWillard added bug Defects or errors in the code. documentation Relating to ReadMEs / gitbook / vignettes / etc. gempyor Concerns the Python core. high priority High priority. next release Marks a PR as a target to include in the next release. labels Dec 10, 2024
Added a unit test to demonstrate the issue described in
#375 (comment)
with respect to the `seir::parameters` section. Appears to be related to
if the parameters are a list or a dict.
@TimothyWillard TimothyWillard force-pushed the hotfix/patching-abilities-documentation branch from ef09f6e to b21cfcc Compare December 10, 2024 20:32
@TimothyWillard
Copy link
Contributor Author

Commit b21cfcc demonstrates the seir::parameters issue described in the first bullet point of #375 (comment). It appears that it can append values when it is a dictionary, but does not do so when it is a list.

@pearsonca
Copy link
Contributor

Commit b21cfcc demonstrates the seir::parameters issue described in the first bullet point of #375 (comment). It appears that it can append values when it is a dictionary, but does not do so when it is a list.

... I hate confuse.

Okay, the short circuit solution here is to hard error rather than warn on top level key collisions. I'm fine with that for now - thoughts?

Corrected an issue where `parse_config_files` would try to merge
top-level keys which comes from `confuse`. Work around is to manually
build a dictionary and then convert that to a `Configuration` object.
For configuration of the outputted yaml.
@TimothyWillard
Copy link
Contributor Author

@pearsonca 02678a3 restores the documented behavior.

@saraloo fe1dc2b adds an --indent option for configuring the appearance of the output.

@TimothyWillard TimothyWillard force-pushed the hotfix/patching-abilities-documentation branch from d397eb1 to ba22f0b Compare December 11, 2024 15:18
flepimop/gempyor_pkg/src/gempyor/cli.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/cli.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/shared_cli.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/tests/cli/test_flepimop_patch_cli.py Outdated Show resolved Hide resolved
@pearsonca
Copy link
Contributor

quick note: i thought we had settings such that -h or --help would work for CLI actions, and also that bare command invocation would trigger the help notes. doesn't seem to be the case -- checking the click docs as to how to have that behavior.

@TimothyWillard TimothyWillard force-pushed the hotfix/patching-abilities-documentation branch from e6ced61 to b34792d Compare December 11, 2024 17:24
Added an internal utility to custom format the yaml representation of a
`confuse.Configuration` object. Creates a custom `yaml.Dumper` class
that contains all of the custom representation changes as to not modify
the `yaml` pkg defaults.
def patch(ctx: click.Context = mock_context, **kwargs) -> None:
"""Merge configuration files

This command will merge multiple config files together by overriding the top level
Copy link
Contributor

Choose a reason for hiding this comment

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

We should frame the example in the way we actually expect people to use the tool: flepimop patch config1.yml config2.yml > confignew.yml. Showing the output still useful so maybe do the piping, followed by a cat?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good point, I've amended the last commit to reflect this.

Changed the help page to use existing files in the `examples/tutorials`
directory rather than construction test configs on the fly per a
suggestion by @pearsonca.
@TimothyWillard TimothyWillard force-pushed the hotfix/patching-abilities-documentation branch from 8de5973 to 0fe483e Compare December 11, 2024 18:36
@TimothyWillard
Copy link
Contributor Author

This PR:

  • Upgrades the warning for overriding top level keys to an error so it is not possible now,
  • Expands the documentation both on the command itself and in the gitbook,
  • No longer writes a separate seir_modifiers_scenarios or outcome_modifiers_scenarios top level key,
  • Custom formatting for the patched yaml file to conform with flepiMoP user expectations, and
  • Unit testing to demonstrate said behavior.

```

You may provide an arbitrary number of separate configuration files to combine to create a complete configuration.

## Caveats

At this time, only `simulate` supports multiple configuration files. Also, the patching operation is fairly crude: configuration options override previous ones completely, though with a warning. The files provided from left to right are from lowest priority (i.e. for the first file, only options specified in no other files are used) to highest priority (i.e. for the last file, its options override any other specification).
At this time, only `simulate` supports multiple configuration files. Also, the patching operation is fairly crude: if multiple configuration files specify the same option, this will yield an error.
Copy link
Contributor

Choose a reason for hiding this comment

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

Propose just a clarifying statement to make things a bit more explicit.

At this time, only simulate directly supports multiple configuration files, and our current patching capabilities only allow for the addition of new sections as given in our tutorials. This is helpful for building models piece-by-piece from a simple compartmental forward simulation, to including outcome probabilities, and finally, adding modifier sections. If multiple configuration files specify the same higher level configuration chunks (e.g., seir, outcomes), this will yield an error.

@@ -32,46 +32,17 @@ you'll get a basic foward simulation of this example model. However, you might a
flepimop simulate config_sample_2pop.yml config_sample_2pop_outcomes_part.yml
```

if want to see what the combined configuration is, you can use the `patch` command:
if want to create a combined configuration (e.g. to check what the combined configuration is), you can use the `patch` command:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should suggest this as a way to start - should look at the config before you run it. Maybe for later, should include that simulate should print out the patched config regardless - so it can be tracked what exactly was run.

Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps change this wording to:

While simulate can run your patched configuration, we also suggest you check your configuration file using the patch command:

Stronger and clearer wording suggested by @saraloo.
@TimothyWillard TimothyWillard merged commit c5bde34 into dev Dec 11, 2024
2 checks passed
@TimothyWillard TimothyWillard deleted the hotfix/patching-abilities-documentation branch December 11, 2024 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Defects or errors in the code. documentation Relating to ReadMEs / gitbook / vignettes / etc. gempyor Concerns the Python core. high priority High priority. next release Marks a PR as a target to include in the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants