[WIP] Add environment management to python package#5656
Draft
chillenzer wants to merge 50 commits intoComputationalRadiationPhysics:devfrom
Draft
[WIP] Add environment management to python package#5656chillenzer wants to merge 50 commits intoComputationalRadiationPhysics:devfrom
chillenzer wants to merge 50 commits intoComputationalRadiationPhysics:devfrom
Conversation
- Add ComputationalWorkflow type to workflow entity - Add programmingLanguage (CWL) as contextual entity - Add conformsTo with RO-Crate 1.2 and Bioschemas profile URIs - Add label and doc to CWL workflow and step templates
715b4f4 to
957875d
Compare
- Add default GPL-3.0 license to RO-Crate - Add version to workflow entity - Add conformsTo pointing to Bioschemas profile - Add creator (Person) to root dataset
- Add default keywords for PIConGPU simulations - Add SoftwareRequirement to CWL build and run tools
- Handle complex CWL types (e.g., arrays) in additionalType - Extract type info from dict-like type definitions - Add input/output formal parameters to workflow metadata
This file contains hidden or 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
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.
Environment management for PIConGPU Python package
Effectively this PR attempts to make our Python package a self-contained installable code. Schematically, the following should work afterwards
without any need for sourcing environments or the like. See below for a full script that I have run successfully on our local dev system. In practice, we all know the hassles of environment management, so this is on a best-effort basis at best. But it is very configurable, so theoretically it should work for every use case (with enough configuration).
This PR does not yet attempt to automatically install dependencies.
User experience
Interface
The environment management is based on a newly introduced runtime configuration dict-like object called
picongpu.rc_params. This approach is strongly inspired by the matplotlib.rc interface. The user can fill this object with configuration parameters that will be used to compose completely self-contained scripts (i.e. including environment setup equivalent to sourcing a profile manually) for runningpic-build, etc.The user has multiple options for providing configuration parameters:
[.]picongpurc.tomlfiles in various places (see matplotlib's precendence rules) to generate the default configuration..picongpurc.tomlor at runtime) setpreset = ...to any of the available profiles frometc/picongpuwhich will generate a profile template from the example profile that the user can fill with a few pieces of information (the detailed values allowed are more permissive and user-friendly, see_rc_params.pyfor details).rc_params["my_key"] = my_valuebefore executing a command. For temporarily alteringrc_paramsit provides a context managerSemantics
Effectively (see
runner.pyfor details), the new approach amounts to compiling a script for runningcommandsasEach of the
rc_params.<property>accesses a property that typically returns a value with the following precedence (see_rc_params.pyfor details):rc_params["profile_content"] = "echo 'Hello World'"will returnecho 'Hello World'asrc_params.profile_content.rc_params["profile_path"]if that was set.rc_params["profile_template_content"]orprofile_template_path.Those scripts are put into
setup_dir/workflow/scriptsand they are self-contained, i.e., for debugging (or less-python-based workflows) they can be run directly from your preferred shell without any reference to Python. If you base your further workflow on Python as well,Runner.build()andRunner.run()will simply run them for you.Setting
picongpurc_pathorpresetat runtime amounts to resetting yourrc_paramsand raises an exception by default if you have already modifiedrc_paramsin the same session. You can change this behaviour byOther values (more interesting for putting into
.picongpurc.tomlor setting non-temporarily) include"raise"(default),"warn"or a custom handler function.Implementation details
The presets are generated from a crude parsing of the
*.profile.examplefiles. I consider this EXTREMELY BRITTLE! In the medium term we'll surely want a more robust way of handling this. In order to pull this off at all, I have made some minor changes (renamings/reformattings) to the example profiles to achieve a slightly more uniform parsing and interface.RCParamsmimics the major semantics of a dictionary. I originally had it inherit directly but always acting mutably onto itself became a major maintenance burden and I switched to managing an internal resource. That implies that the dict-interface might be incomplete. Just ask if you need more... that's probably easy to add.I've added the
templatesandcoresub-package. Their only python-side functionality is to provide the path to the template/C++ files for reference in other parts of the code. In addition, upon non-editable installation all relevant C++ files are copied intocoreand thecore.path()just points to itself. In editable installation, nothing is copied andcore.path()points to the top-level repo.As a build backend I've switched to
hatchlingwhich I found on the internet to be recommended for non-trivial file arrangements and install hooks. The former is already heavily used, the latter will probably come in handy in the future. Only annoyance seems to be that it treats thesdist(source distribution) andwheel(binary distribution) targets completely independent, so configuration apparently has to be duplicated. But maybe I just overlooked an obvious switch here.The not-too-coupled semantics of the interface are tested in unit tests. Please refer to them for more details on the interface semantics until we've written proper documentation.
Full scripts that worked for me
Running locally
with
/path/to/my/profile_templatecontaining something likeRunning on HAL
This produces the results in a temporary directory, roughly
/tmp/<username>/pypicongpu-...-{setup,run}....Please test this!
For testing, I'd start with running locally. Always install in non-editable mode
pip install lib/pythonin order to make sure you're not relying on your local clone of the repository anymore.my_picongpu.profilethat allows to run the pre-this-PR code, then check out the new code and putprofile_path = "my_picongpu.profile"into.picongpurc.tomlin your current working directory (or any parent of it, e.g., your home directory). There should be no need to source this profile from now on. This will not have gained you much because your profile still relies on your local copy of the source code.export PICSRC=...line in that profile toexport PICSRC="{{{pic_src_path}}}"and change your.picongpurc.tomltoprofile_template_path = "my_picongpu.profile". This should now point the corresponding scripts at the installed code. You should now be independent of your original source location.bashprofile example, you could try to run this directly viapreset = "bash"in your.picongpurc.toml. Otherwise, skip this step.Afterwards, please go to as many systems as you can and try to run a small test job there. If we've got an example for this system, you can simply start from
preset = "<system name>"in your.picongpurc.toml. It will raise an exception telling you about any missing information it needs (typicallyauthor = "<name>"andemail = "<my email>"). Fill in this information in your.picongpurc.tomland you might be good to go. (If we have multiple*.profile.examplefiles, you might need to be more precise:preset = "bash-devServer-hzdr/gpu_a30_picongpu". You'll figure out the details.)