Thin Python wrapper for NextGenPB
Project description
ngpb4py
ngpb4py is a thin Python wrapper for NextGenPB.
Features
- Typed configuration, runner, and result objects
- Container-based execution with Apptainer as the default runtime
- Structured parsing for documented log sections and potential output files
- Per-run scratch directories with automatic cleanup on successful runs
Installation
To install the latest stable version run:
pip install ngpb4py
Warning: A supported container runtime must be installed on your system. See the Apptainer installation guide if you plan to use Apptainer or Singularity.
By default ngpb4py searches your system PATH for the Apptainer executable.
To specify a custom Apptainer path, pass apptainer_path to NgpbRunner:
runner = NgpbRunner(apptainer_path="/custom/path/to/apptainer")
Quick Start
from ngpb4py import NgpbConfig, NgpbRunner
config = NgpbConfig.from_prm("examples/exercise1/options.prm")
result = NgpbRunner(nproc=16).run(
config=config,
workdir="/tmp/ngpb-scratch",
verbose=3,
)
print(result.log.grid.total_nodes)
print(result.log.energies.total_electrostatic_energy_kt)
phi_surf = result.parsed_outputs["phi_surf.txt"]
if phi_surf:
print(phi_surf.coordinates[:10])
print(phi_surf.potentials[:10])
Running Examples
The repository includes runnable examples under examples/ that mirror the
NextGenPB tutorial.
examples/exercise1/examples/exercise2/examples/exercise3/examples/exercise4/
Run an example from the repository root with Python after installing the package:
python examples/exercise1/exercise1.py
Testing
The test suite uses pytest, which is not installed by default with the base
package. Install the development dependencies first:
uv sync --group dev
Then run the full test suite:
uv run --group dev python -m pytest
Runtime Backends
ngpb4py always runs NextGenPB in a container. By default, NgpbRunner uses
Apptainer with the published SIF image:
https://github.com/concept-lab/NextGenPB/releases/download/NextGenPB_v1.0.0/NextGenPB.sif
If you prefer Docker, build or provide a Docker image and pass the image name to
NgpbRunner.
If you want to keep using Apptainer or Singularity with a different image, pass
an alternate local or remote .sif via container_image:
runner = NgpbRunner(
container_runtime="apptainer",
container_image="/data/images/NextGenPB-custom.sif",
)
Remote .sif URLs are downloaded and cached automatically for
Apptainer-compatible runtimes.
To add flags directly to apptainer exec, pass container_exec_args:
runner = NgpbRunner(
nproc=4,
container_exec_args=["--nv", "--containall"],
)
Working With Results
NgpbResult exposes the parsed NextGenPB terminal log through result.log.
Each documented section is available as a typed object when present in the
output:
result.log.systemresult.log.domainresult.log.surfaceresult.log.gridresult.log.solverresult.log.energies
Only parsed values are exposed on these section objects. The parser does not
attach raw per-section log text to result.log.*.
When NextGenPB writes any of the following files, NgpbResult parses them and
exposes them through result.parsed_outputs:
phi_surf.txtphi_nodes.txtphi_on_atoms.txt
Each parsed file is returned as a PotentialSampleSet with:
coordinates:List[List[float]], where each item is[x, y, z]potentials:List[float], where each item matches the corresponding coordinate
Run Behavior and Verbosity
The workdir argument is treated as a scratch parent directory. Each call to
run() creates a unique child directory so concurrent runs do not collide.
Successful runs are cleaned up by default. To keep generated files, logs, and
staged inputs on disk, pass keep_files=True. On failures, the per-run
directory is kept automatically for debugging.
Use the runner verbose argument, or set NgpbRunner(verbosity=...), to
control wrapper logging:
0: warnings and errors only1: high-level run progress2: debug logging from the wrapper3: debug logging plus streaming backend output when supported
This affects the wrapper logs printed by ngpb4py. Parsed terminal output
remains available afterwards through result.log.
Contributing
Clone this repository and run the following from root of the repository:
# Create and install a virtual environment
uv sync --python 3.10 --all-extras
# Activate the virtual environment
source .venv/bin/activate
# Install the pre-commit hooks
pre-commit install --install-hooks
- This project follows the Conventional Commits standard to automate Semantic Versioning and Keep A Changelog with Commitizen.
- Run
poefrom within the development environment to print a list of Poe the Poet tasks available to run on this project. - Run
uv add {package}from within the development environment to install a run time dependency and add it topyproject.tomlanduv.lock. Add--devto install a development dependency. - Run
uv sync --upgradefrom within the development environment to upgrade all dependencies to the latest versions allowed bypyproject.toml. Add--only-devto upgrade the development dependencies only. - Run
cz bumpto bump the package's version, update theCHANGELOG.md, and create a git tag. Then push the changes and the git tag withgit push origin main --tags.
License
This repository and the published Python package ngpb4py are licensed under
the GNU GPL v3.0.
ngpb4py is a separate Python wrapper project. It is not the NextGenPB
solver itself, and its license statement applies to the wrapper code in this
repository.
NextGenPB is the upstream solver project maintained at
https://github.com/concept-lab/NextGenPB. That project is distributed
separately, includes its own copyright notices, and is also marked there as
GPL-3.0 licensed. When you use ngpb4py, you should distinguish between:
ngpb4py: this Python wrapper package and repositoryNextGenPB: the external solver, container image, documentation, and source code provided by the upstream project
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 ngpb4py-0.3.0.tar.gz.
File metadata
- Download URL: ngpb4py-0.3.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c6fb2bf2087515e14d317f7b5f63cb7c40bbf1125a9be73f72220259be7b048
|
|
| MD5 |
d14296c21dbd806fc56dd2468c3e1372
|
|
| BLAKE2b-256 |
ec648fbd77a136e84cc1bf4cf4f56e2c8a72f7fd0afd75df12fded9012d41bd0
|
File details
Details for the file ngpb4py-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ngpb4py-0.3.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd8ce7250579d32d4ccda9774d9abe83eafb273255cd79738a2a111dbc9a0952
|
|
| MD5 |
013d7c8ca389ca453260b987c6b7f719
|
|
| BLAKE2b-256 |
b60cb0f22eafa31bf2061928c722d753b79875780bd0dfc2e3d82a70ede032df
|