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

Improved fv3 logging #225

Merged
merged 34 commits into from
Apr 13, 2020
Merged

Conversation

nbren12
Copy link
Contributor

@nbren12 nbren12 commented Apr 8, 2020

This PR introduces several improvements to the logging capability of our prognostic run image

  • include upstream changes to disable output capturing in fv3config.fv3run
  • Add capture_fv3gfs_func function. When called this capture the raw fv3gfs outputs and re-emit it as DEBUG level logging statements that can more easily be filtered.
  • Refactor runtime to external/runtime/runtime. This was easy since it did not depend on any other module in fv3net. (except implicitly the code in fv3net.regression which is imported when loading the sklearn model with pickle).

@nbren12 nbren12 changed the base branch from master to develop-one-steps April 8, 2020 01:39
Copy link
Contributor

@frodre frodre left a comment

Choose a reason for hiding this comment

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

There's a lot of good stuff in here, thanks! I had some tests failing on my machine with fv3config.fv3run, but I that's probably something about the installation on my system, and it looks like those are skipped on CI anyways.

I think the main comment worth thinking about is whether it's better to have the list of functions we're adjusting output for should be defined within fv3net (could break if there are function name changes upstream or be incomplete), or designated in fv3gfs (lose the explicit definition of what's being altered here).

Otherwise, there are a few clean-up items to attend to and some general comments/questions. Otherwise, LGTM!

@@ -3,7 +3,7 @@
#################################################################################
# GLOBALS #
#################################################################################
VERSION ?= v0.1.0-a1
VERSION ?= $(shell git rev-parse HEAD)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just thinking through this change. Building locally, we would get a unique version tied to our current commit. It makes things a bit tricky if we want to re-use a previous revision, but nor more tricky than looking up the tag. It doesn't affect the CI builds because those adjust VERSION on their own. Seems fine to me and I like the build uniqueness tag linking to git commits.

Copy link
Contributor Author

@nbren12 nbren12 Apr 13, 2020

Choose a reason for hiding this comment

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

Yah. I think we should also be tagging our CI images with commit. I remember seeing various places online that that is recommended workflow that maximizes reproducibility since tags can change. I am more worried about building images from a dirty working tree.

@@ -47,6 +47,7 @@ dependencies:
- bokeh=1.4
- backoff
- pip:
- poetry
Copy link
Contributor

Choose a reason for hiding this comment

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

Starting to use poetry! If we expand the use eventually, we can adjust the pytest_default caching a bit differently with the availability of the lockfile, potentially able do partial updates. Nice addition towards this with a working example in the runtime package.

Copy link
Contributor Author

@nbren12 nbren12 Apr 13, 2020

Choose a reason for hiding this comment

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

Yah. It would be great to use poetry in the images too.

from runtime import __version__


def test_version():
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't seen a test like this before? Is it just for the sake of testing an import? Or was there weird stuff in the versions.

On a second note, maybe we should include the version bump integration in setup.cfg from the getgo so stuff like this is easy to catch and update automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't think we have decided whether the versions in external should be the same as fv3net. vcm isn't anywhere in the setup.cfg either.

"""Surpress stderr and stdout from all fv3gfs functions"""
import fv3gfs # noqa

for func in ["step_dynamics", "step_physics", "initialize", "cleanup"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we'd want to keep track of functions that have outputs within fv3gfs and reference that list here? That would prevent this list from becoming desync-ed from the package function names.

OTOH, it's nice to have an explicit list here of what's being decorated. We could add logging to get the same information.

Copy link
Contributor Author

@nbren12 nbren12 Apr 13, 2020

Choose a reason for hiding this comment

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

I think this is OK atm since those functions are part of the public API of fv3gfs, and that package has a pretty clear versioning strategy. Ultimately, I think this logic should become part of fv3gfs-python, which will mitigate your concern about this code become out of date.

@@ -286,6 +183,16 @@ def submit_jobs(
logger.info(pprint.pformat(locals()))
# kube kwargs are shared by all jobs
kube_kwargs = get_run_kubernetes_kwargs(one_step_config["kubernetes"], config_url)
kube_kwargs["capture_output"] = False
kube_kwargs["memory_gb"] = 6.0
Copy link
Contributor

Choose a reason for hiding this comment

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

These look like some new defaults? If so, there's a defaults dictionary you can throw them in this file above.

https://github.com/VulcanClimateModeling/fv3net/blob/60795240f4d2147132df44fca48fdbfe17440116/fv3net/pipelines/kube_jobs/one_step.py#L24

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. Thanks, I added it.

@@ -152,6 +174,7 @@ def mock_batch_api():
return num_jobs, num_success, mock_api, labels


@pytest.mark.skip()
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably good to get rid of the mock monstrosity I wrote given the new testing strategy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha. I remember being pretty into mocks at the time it was written. Now, I think a much better strategy for testing K8s resources would be to spin-up a small cluster with minikube or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted the mock.

Comment on lines +9 to +13
def capture_stream(stream):
"""fork is not compatible with mpi so this won't work

The wait line below hangs indefinitely.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth keeping around if it doesn't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kind of want to. It took me a full work day to figure out how to do it without a tempfile! :(

@frodre
Copy link
Contributor

frodre commented Apr 10, 2020

I meant for that to be a general comment review without approval or requested changes, but I think it stands as is fine.

@@ -33,30 +32,19 @@


def timesteps_to_process(
Copy link
Contributor

Choose a reason for hiding this comment

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

The merge conflict here and in orchestrate_submit_jobs.sh is with an additional argument I added to specify the start index in addition to number of steps, I can send you the resolved code I got working on my local

logger = logging.getLogger(logger_name)
out.seek(0)
for line in out:
logger.debug(line.strip().decode("UTF-8"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This worked great to simplify the output to the gcs k8s UI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will make a github issue to refactor this code to fv3gfs-python.

@nbren12 nbren12 merged commit 332eb79 into develop-one-steps Apr 13, 2020
@nbren12 nbren12 deleted the feature/improved-one-step-logging branch April 13, 2020 20:46
nbren12 added a commit that referenced this pull request Apr 13, 2020
* Feature/one step save baseline (#193)

This adds several features to the one-step pipeline

- big zarr. Everything is stored as one zarr file
- saves physics outputs
- some refactoring of the job submission.

Sample output: https://gist.github.com/nbren12/84536018dafef01ba5eac0354869fb67

* save lat/lon grid variables from sfc_dt_atmos (#204)

* save lat/lon grid variables from sfc_dt_atmos

* Feature/use onestep zarr train data (#207)

Use the big zarr from the one step workflow as input to the create training data pipeline

* One-step sfc variables time alignment (#214)

This makes the diagnostics variables appended to the big zarr have the appropriate step and forecast_time dimensions, just as the variables extracted by the wrapper do.

* One step zarr fill values (#223)

This accomplishes two things: 1) preventing true model 0s from being cast to NaNs in the one-step big zarr output, and 2) initializing big zarr arrays with NaNs via full so that if they are not filled in due to a failed timestep or other reason, it is more apparent than using empty which produces arbitrary output.

* adjustments to be able to run workflows in dev branch (#218)

Remove references to hard coded dims and data variables or imports from vcm.cubedsphere.constants, replace with arguments.
Can provide coords and dims as args for mappable var

* One steps start index (#231)

Allows for starting the one-step jobs at the specified index in the timestep list to allow for testing/avoiding spinup timesteps

* Dev fix/integration tests (#234)

* change order of required args so output is last

* fix arg for onestep input to be dir containing big zarr

* update end to end integration test ymls

* prognostic run adjustments

* Improved fv3 logging (#225)

This PR introduces several improvements to the logging capability of our prognostic run image

- include upstream changes to disable output capturing in `fv3config.fv3run`
- Add `capture_fv3gfs_func` function. When called this capture the raw fv3gfs outputs and re-emit it as DEBUG level logging statements that can more easily be filtered.
- Refactor `runtime` to `external/runtime/runtime`. This was easy since it did not depend on any other module in fv3net. (except implicitly the code in `fv3net.regression` which is imported when loading the sklearn model with pickle).
- updates fv3config to master

* manually merge in the refactor from master while keeping new names from develop (#237)

* lint

* remove logging from testing

* Dev fix/arg order (#238)

* update history

* fix positional args

* fix function args

* update history

* linting

Co-authored-by: Anna Kwa <annak@vulcan.com>
Co-authored-by: brianhenn <brianhenn@gmail.com>
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.

3 participants