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 build workflow #272

Merged
merged 39 commits into from
Mar 23, 2023
Merged

improved build workflow #272

merged 39 commits into from
Mar 23, 2023

Conversation

bkmartinjr
Copy link
Contributor

@bkmartinjr bkmartinjr commented Mar 17, 2023

This implements most of what is required to complete #265. Specifically, it dockerizes and automates the full census build steps 1-3:

  1. verifies that the host meets requirements (memory, free disk, etc)
  2. performs build & validation using cell_census_builder package, with official default args
  3. generate summary and summary diff from latest build

It stops short of the remaining steps for a full release:

  • copies build & build logs to S3
  • performs release (release.json file edit) to latest
  • cleans up outdated releases (including removing from release.json)
  • re-eval notebooks

Changes in this PR:

  • Dockerized the Census builder
  • Add GHA to build the docker image
  • cell_census_builder converted to installable package, with sub-modules that perform different build steps. Each sub-module has a separate __main__ to allow for continued stand-alone use. Used a src layout for easy packaging with setuptools
    • Added new top-level CensusBuildArgs, CensusBuildConfig and CensusBuildState which unifies the static and dynamic state across all builder sub-modules. This replaces the use of argparse.Namespace for configuration.
    • Added a new top-level main that implements the official "census" build workflow, with defaults appropriate for full-census builds.
    • Reorganized previous build code into a build_soma sub-module. This includes splitting __main__.py into multiple files, moving all files down into a sub-module called build_soma, etc.
    • Added new sub-module host_validation which performs checks on host config/resources. Intended to be used as a prologue to a build, e.g., confirming sufficient memory
    • Moved census_summary into the package as a sub-module
  • Moved scripts unrelated to build workflow (e.g., swapon) into tools/scripts as they will be used outside of the eventual container
  • revised tests around new package organization

Notes for reviewers: no major changes to the build or summary modules. Changes are primary around configuration and creating a new top-level workflow that has defaults suitable for the full Census build. There is also other cleanup and reorganization that could be done (e.g., breaking up the build_soma sub-module into smaller chunks), but I'd rather do that progressively, as this PR is getting way too big....

@codecov
Copy link

codecov bot commented Mar 17, 2023

Codecov Report

Merging #272 (509ffd2) into main (91d7a12) will decrease coverage by 1.95%.
The diff coverage is 81.77%.

@@            Coverage Diff             @@
##             main     #272      +/-   ##
==========================================
- Coverage   93.44%   91.49%   -1.95%     
==========================================
  Files          34       41       +7     
  Lines        2028     2223     +195     
==========================================
+ Hits         1895     2034     +139     
- Misses        133      189      +56     
Flag Coverage Δ
unittests 91.49% <81.77%> (-1.95%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...c/cell_census_builder/build_soma/census_summary.py 100.00% <ø> (ø)
...der/src/cell_census_builder/build_soma/datasets.py 95.34% <ø> (ø)
...lder/src/cell_census_builder/build_soma/globals.py 100.00% <ø> (ø)
...l_census_builder/build_soma/summary_cell_counts.py 94.11% <ø> (ø)
...rc/cell_census_builder/build_soma/tissue_mapper.py 84.81% <ø> (ø)
...builder/src/cell_census_builder/build_soma/util.py 87.14% <ø> (ø)
...census_builder/src/cell_census_builder/__init__.py 60.00% <60.00%> (ø)
...sus_builder/src/cell_census_builder/build_state.py 60.78% <60.78%> (ø)
...der/src/cell_census_builder/build_soma/__main__.py 66.66% <66.66%> (ø)
..._census_builder/src/cell_census_builder/logging.py 73.07% <73.07%> (ø)
... and 19 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@bkmartinjr bkmartinjr marked this pull request as ready for review March 22, 2023 19:33
.github/workflows/py-build.yml Show resolved Hide resolved
@@ -68,7 +68,7 @@ def load_manifest_from_CxG() -> List[Dataset]:
logging.info(f"Found {len(datasets)} datasets, in {len(collections)} collections")

# load per-dataset schema version
with concurrent.futures.ThreadPoolExecutor(max_workers=16) as tp:
with concurrent.futures.ThreadPoolExecutor(max_workers=32) as tp:
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason for which this isn't parametrized as well?

Copy link
Contributor Author

@bkmartinjr bkmartinjr Mar 22, 2023

Choose a reason for hiding this comment

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

no good reason, other than we had no prior need. I'll add a config for it so it can be overridden. It can't use the standard worker config, as it controls the concurrent HTTP requests. The only reason we have any value here (rather than use the thread pool default) is to keep from overwhelming the Discover REST backend.

Copy link
Member

Choose a reason for hiding this comment

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

We could call it max_io_workers.

Copy link
Contributor Author

@bkmartinjr bkmartinjr Mar 22, 2023

Choose a reason for hiding this comment

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

with the recent improvements to the Discover backend, this works fine using the system defaults for ThreadPoolExecutor so I simply removed the config entirely.

```
working_dir:
|
+-- config.yaml # build config (user provided, read-only)
Copy link
Member

Choose a reason for hiding this comment

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

Could be useful to provide an example config.yaml that can be copied as necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure. later info in this doc points the user at the build_state.py file. And by default you should not specify a config file if doing the standard census build. It is only for dev reasons that you would use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

example added, plus verbiage about not needing to provide a config for the standard census build

Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to dev-config.yaml?

Copy link
Contributor Author

@bkmartinjr bkmartinjr Mar 23, 2023

Choose a reason for hiding this comment

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

I would rather leave as-is. It is the config, for any purpose. I just have defaults set so that it isn't required in our current workflow, but I can easily imagine situations where it is used in the future.

that said, if you feel strongly, I'm not going to force this issue :-)

Copy link
Collaborator

@atolopko-czi atolopko-czi left a comment

Choose a reason for hiding this comment

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

LGTM, but made a few usability/doc-related comments, plus:

```
working_dir:
|
+-- config.yaml # build config (user provided, read-only)
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to dev-config.yaml?

```
$ mkdir /tmp/census-build
$ chmod ug+s /tmp/census-build # optional, but makes permissions handling simpler
$ docker run --mount type=bind,source="`pwd`/tmp/census-build",target='/census-build' cell-census-builder
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$ docker run --mount type=bind,source="`pwd`/tmp/census-build",target='/census-build' cell-census-builder
$ docker run --mount type=bind,source="/tmp/census-build",target='/census-build' cell-census-builder

Copy link
Collaborator

Choose a reason for hiding this comment

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

rm $ prompts for easier copy & paste; also add markdown type: "```shell" as first line (here & above)


https://docs.google.com/document/d/1GKndzCk9q_1SdYOq3BeCxWgp-o2NSQkEmSBaBPKnNI8/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unless running from Batch is right around the corner, worth keeping this link or moving its contents here. E.g. you still need to know how to provision EC2 instance and setup swap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a link to an obsolete schema spec, which I replaced with the correct link. It was not a build process doc, which has never been part of this README (and probably should not IMHO given that it contains internal infra info).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ps. once I get all this landed, and refined, I will update the "manual build process" doc, not linked here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, great!

docker system prune
docker rm -f $(docker ps -aq)
docker rmi -f $(docker images -q)
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move into a Makefile target for convenience?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

excellent idea.

from importlib import metadata
except ImportError:
# for python <=3.7
import importlib_metadata as metadata # type: ignore[no-redef]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: support for <=3.7 doesn't seem necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and the pyproject.toml defines supported releases as 3.9 and 3.10, so this change is consistent with that.

@bkmartinjr
Copy link
Contributor Author

The docker build failed on M1 ("numpy not found"), so attempted on EC2 Ubuntu instance, which worked. (Did not troubleshoot M1, since I don't think it's necessary to be able to build locally.)

@atolopko-czi - can you provide more details on this failure? While I agree we do not support M1 Macs, this is an unexpected failure as numpy is clearly listed in the pyproject.toml dependencies. I would have expected that it would blow up trying to find an M1 wheel for tiledbsoma, which AFAIK does not yet exist.

Copy link
Collaborator

@atolopko-czi atolopko-czi left a comment

Choose a reason for hiding this comment

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

LGTM!

Will recreate the numpy error later and report back.


https://docs.google.com/document/d/1GKndzCk9q_1SdYOq3BeCxWgp-o2NSQkEmSBaBPKnNI8/
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, great!

@bkmartinjr bkmartinjr merged commit d9bd1eb into main Mar 23, 2023
@bkmartinjr bkmartinjr deleted the bkmartinjr/265-build-workflow branch March 23, 2023 16:56
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