Python wrapper for LPJ-Guess experiment runner (via pythonnet + .NET 9)
Project description
lpjguess-runner
Python wrapper for LPJ-Guess experiment runner (via pythonnet + .NET 9)
Build
Prerequisites:
- .NET 9 SDK
- Python 3.11 (if building wheel)
# Clone the repository with submodules
git clone --recurse-submodules git@github.com:hie-dave/lpjg-gui.git
make wheel
Install
- Prerequisites: .NET 9 runtime
From PyPI
pip install lpjguess-runner
From Source
make install # install globally
make install-venv VENV=.venv # install into a local virtual environment (default: .venv)
make install-user # install for the current user
Concepts and Workflow
This package is a thin Python wrapper around a .NET job runner for LPJ-Guess. A typical workflow configures a run, defines which simulations to execute, and optionally customises how progress and model output are handled.
-
Run settings: A
RunSettingsobject specifies the LPJ-Guess executable path, output directory, input module, CPU count, and job name. -
Simulations: A list of
Simulationobjects describes variations to apply to base instruction files (for example changing top-level parameters or PFT block parameters). The helpersimulation(name, factors)creates these objects. -
Instruction files and PFTs: A list of
.insfiles and PFT names to run. Each instruction file will be run once for each defined simulation. -
Progress and output handling (optional): Objects can be supplied to receive progress updates and model stdout/stderr. For convenience, this package exports Python base classes that already implement the required .NET interfaces, so only the required methods need to be overridden:
CustomProgressReporter.ReportProgress(percent, elapsed, ncomplete, njob)CustomOutputHelper.ReportOutput(jobName, output)/ReportError(...)
See the "Customising Progress and Output" section below for more details.
-
Outputs: Files are written under the output directory specified in
RunSettings. The structure depends on the LPJ-Guess configuration and runner settings. -
Result:
run_simulations(...)returns anExperimentResultwith summary counts (TotalJobs,SuccessfulJobs,FailedJobs) andErrorif present.
Notes for Python users:
- When using custom progress/output handlers, the overriden hooks may be called from background threads; handlers should therefore be fast and thread-safe.
- If only console output is required, use
ConsoleProgressReporter()andConsoleOutputHelper()and skip writing custom classes. - To customise behavior, subclass the provided bases rather than implementing .NET interfaces directly.
Example Usage
from lpjguess_runner import *
run_settings = RunSettings.Local(
"/path/to/guess/executable",
"/path/to/output/directory",
"nc", # input module
4, # cpu count
"job_name")
simulations = [
simulation("nindiv_max_0_sla_26", [ # Run all .ins files with:
TopLevelParameter("wateruptake", "wcont"), # - wateruptake = wcont
BlockParameter("pft", "MRS", "sla", "26") # - SLA of "MRS" pft set to 26
]),
simulation("nindiv_max_1_sla_39", [ # Run all .ins files with:
TopLevelParameter("wateruptake", "rootdist"), # - wateruptake = rootdist
BlockParameter("pft", "MRS", "sla", "39") # - SLA of "MRS" pft set to 39
]),
]
ins = ["/path/to/file1.ins", "/path/to/file2.ins"]
pfts = ["MRS"]
result = run_simulations(run_settings,
simulations,
ins,
pfts,
ConsoleProgressReporter(), # Write progress messages to stdout
ConsoleOutputHelper()) # Propagate subprocess output to stdout
print(f"Total jobs: {result.TotalJobs}")
print(f"Successful jobs: {result.SuccessfulJobs}")
print(f"Failed jobs: {result.FailedJobs}")
print(f"Error: {result.Error}")
Customising Progress and Output
The default helpers ConsoleProgressReporter() and ConsoleOutputHelper()
propagate progress and model stdout/stderr to stdout. For custom behavior,
subclass the Python base classes exported by this package:
CustomProgressReporter(implements.NETIProgressReporter).CustomOutputHelper(implements.NETIOutputHelper).
These hide pythonnet interop details so only the necessary methods must be overridden in subclasses.
Example: capture stdout/stderr and print compact progress
from lpjguess_runner import *
import threading
class MyOutput(CustomOutputHelper):
def __init__(self):
super().__init__()
self.stdout = {}
self.stderr = {}
self._lock = threading.Lock()
def ReportOutput(self, jobName, output):
with self._lock:
self.stdout.setdefault(jobName, []).append(output)
def ReportError(self, jobName, output):
with self._lock:
self.stderr.setdefault(jobName, []).append(output)
class MyProgress(CustomProgressReporter):
def ReportProgress(self, percent, elapsed, ncomplete, njob):
print(f"[{elapsed}] {ncomplete}/{njob} ({percent:.1f}%)")
out = MyOutput()
pr = MyProgress()
result = run_simulations(run_settings, simulations, ins, pfts, pr, out)
Notes
- Methods may be called from background threads; keep handlers fast and thread-safe.
- Output can be frequent; consider buffering or filtering.
- Advanced: if implementing the .NET interfaces directly instead of subclassing
these bases, the class must inherit from
System.Object, callObject.__init__, and set a valid__namespace__(for example"LpjGuess.Runner.Python"). Using the provided base classes is recommended.
Results and Outputs
run_simulations(...) returns an ExperimentResult with at least:
TotalJobsSuccessfulJobsFailedJobsError
Files are written under the output directory provided to RunSettings.Local.
If jobs produce per-run subdirectories, those will appear under that directory.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lpjguess_runner-1.0.0-py3-none-win_amd64.whl.
File metadata
- Download URL: lpjguess_runner-1.0.0-py3-none-win_amd64.whl
- Upload date:
- Size: 1.0 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff2a3441eab6f6327f3e63feb53174275fc3ed656eca68b5bbbf2d3005bc054f
|
|
| MD5 |
c04c307987e40a1d386df97ab2098937
|
|
| BLAKE2b-256 |
d5b605ba5d368b094aa48fbc51fcab8fcd0b3376ccb077c0534ac733bc2d4f47
|
Provenance
The following attestation bundles were made for lpjguess_runner-1.0.0-py3-none-win_amd64.whl:
Publisher:
ci.yml on hie-dave/lpjg-gui
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lpjguess_runner-1.0.0-py3-none-win_amd64.whl -
Subject digest:
ff2a3441eab6f6327f3e63feb53174275fc3ed656eca68b5bbbf2d3005bc054f - Sigstore transparency entry: 709570793
- Sigstore integration time:
-
Permalink:
hie-dave/lpjg-gui@dd6f58b1304029a0f9e774613def1b7d076f1e34 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/hie-dave
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@dd6f58b1304029a0f9e774613def1b7d076f1e34 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lpjguess_runner-1.0.0-py3-none-manylinux2014_x86_64.whl.
File metadata
- Download URL: lpjguess_runner-1.0.0-py3-none-manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d6fe7f5fe41a7f7d9d4397aa6cd845c573f35d715f3d267413dd6fb27c4ef63
|
|
| MD5 |
faeb6f16c5249b63457d1dd79a6d696e
|
|
| BLAKE2b-256 |
c25cf0a7d96d5552fdba65ea39b7d780114b89a8d25e6ea5b432bc5b38d919ce
|
Provenance
The following attestation bundles were made for lpjguess_runner-1.0.0-py3-none-manylinux2014_x86_64.whl:
Publisher:
ci.yml on hie-dave/lpjg-gui
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lpjguess_runner-1.0.0-py3-none-manylinux2014_x86_64.whl -
Subject digest:
0d6fe7f5fe41a7f7d9d4397aa6cd845c573f35d715f3d267413dd6fb27c4ef63 - Sigstore transparency entry: 709570806
- Sigstore integration time:
-
Permalink:
hie-dave/lpjg-gui@dd6f58b1304029a0f9e774613def1b7d076f1e34 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/hie-dave
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@dd6f58b1304029a0f9e774613def1b7d076f1e34 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lpjguess_runner-1.0.0-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: lpjguess_runner-1.0.0-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.0 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1afac34f0cbca015fa120a88ebde74b053c758eb5522dde303d933df0cabcea9
|
|
| MD5 |
11fb6b237ca3563204bfaec84d0df907
|
|
| BLAKE2b-256 |
726e6d8f3e9ddf6249ccfadaaf4c286a7cdaa1abe5db8d645d94ce18d194b622
|
Provenance
The following attestation bundles were made for lpjguess_runner-1.0.0-py3-none-macosx_11_0_arm64.whl:
Publisher:
ci.yml on hie-dave/lpjg-gui
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lpjguess_runner-1.0.0-py3-none-macosx_11_0_arm64.whl -
Subject digest:
1afac34f0cbca015fa120a88ebde74b053c758eb5522dde303d933df0cabcea9 - Sigstore transparency entry: 709570779
- Sigstore integration time:
-
Permalink:
hie-dave/lpjg-gui@dd6f58b1304029a0f9e774613def1b7d076f1e34 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/hie-dave
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@dd6f58b1304029a0f9e774613def1b7d076f1e34 -
Trigger Event:
push
-
Statement type: