Skip to main content

pyPenred - Python Bindings for PenRed

PenRed logo

https://penred.github.io/PenRed/pyPenred/ Python interface for the [PenRed](https://github.com/PenRed/PenRed) Monte Carlo radiation transport simulator, enabling programmatic control and automation.

Key Features

Currently pyPenred offers:

  • Direct Simulation Control
    Run PenRed simulations directly from Python scripts

  • Configuration management
    Convert between PenRed native configuration format, YAML and Python dicts

  • Workflow Automation
    Chain multiple simulations with parameter sweeps

  • External Software Integration
    Embed PenRed in custom applications and pipelines

Installation

pyPenred can be installed directly from pip as a regular package:

pip install pyPenred

From Source

If the user wants to modify the source code or compile it with native optimizations, another option consists on compiling the binding locally using the installPyPenred scripts in the PenRed repository src folder.

The requirements to compile the code are:

  • Python 3.8+ development headers
  • CMake 3.12+
  • C++14 compatible compiler

If the requirements are fulfilled, just run the corresponding script.

Linux/macOS:

./installPyPenred.sh

Windows:

installPyPenred.bat

Configuration Format Conversion

pyPenred implements a bi-directional conversion between PenRed's native configuration format and Python dictionaries. Parameter paths with slashes map to nested dictionary structures:

Native Format Python Dictionary Equivalent
/geometry/phantom/material config['geometry']['phantom']['material']

Basic Usage

Running a Simulation

To run a simulation using a configuration file located in the current folder, named config.in, just use:

import pyPenred
pyPenred.runFromFile("config.in")  # Supports both native and YAML formats

Modifying Configurations

To modify an existing configuration file (config.in) either in regular PenRed or YAML formats, the following code can be used:

config = pyPenred.readConfigFile("config.in") # Load the file as a dictionary
config['path']['to']['modify'] = 42  # Modify parameters
pyPenred.writeConfigFile("modified.in", config)  # Export to native format

Complete Example

A more complete example can be found in the runFromFile function code. This one configures the simulation and runs it asynchronously reporing the simulation state in regular intervals. Take into account that this function is defined within the pyPenred module. Therefore, the pyPenred module prefix must be used in regular scripts:

def runFromFile(configFile = "config.in",
                statusTime = 20,
                configLog = "config.log",
                simulationLog = "simulation.log"):
    '''
    Configures and runs a simulation from the specified file.
    Reports the simulation status periodically.
    '''

    #Set logs
    simulation.setConfigurationLog(str(configLog))
    simulation.setSimulationLog(str(simulationLog))

    #Create simulation object
    simu = simulation.create()

    #Try to get the configuration from yaml or penred internal format
    try:
        f = open(configFile)
        d = yaml.load(f, Loader=yaml.SafeLoader)
        simu.configure(d)
    except:
        simu.configFromFile(configFile)
        
    print("Configuration set\n")

    #Start the simulation asynchronously
    simu.simulate(True)

    #Simulation started, check status every 30 seconds
    print("Simulation started\n")
    while simu.isSimulating():
        try:
            time.sleep(statusTime)
        except:
            time.sleep(20)
        status = simu.stringifyStatus()
        for e in status:
            print(e)

    print("Simulation finished")

Documentation

📚 pyPenred API

📚 PenRed Documentation

Support

🐞 Report Issues
💬 Discussion Forum

API

To build the authomatic API documentation, you need the sphinx package:

pip install sphinx furo sphinx-copybutton sphinx-autodoc-typehints sphinxcontrib-napoleon myst-parser

once installed, build the documentation running the following instructions inside the docs folder

make html

Finally, the documentation will be available opening the file docs/build/html/index.html with a web browser.

Metadata

Release files for pyPenred 1.15.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pyPenred 1.15.2.0
File
pypenred-1.15.2.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pypenred-1.15.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
pypenred-1.15.2.0-cp314-cp314-macosx_14_0_x86_64.whl CPython 3.14 CPython 3.14 macOS 14.0+ x86-64 Details
pypenred-1.15.2.0-cp314-cp314-macosx_14_0_arm64.whl CPython 3.14 CPython 3.14 macOS 14.0+ ARM64 Details
pypenred-1.15.2.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pypenred-1.15.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
pypenred-1.15.2.0-cp313-cp313-macosx_14_0_x86_64.whl CPython 3.13 CPython 3.13 macOS 14.0+ x86-64 Details
pypenred-1.15.2.0-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details
pypenred-1.15.2.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pypenred-1.15.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
pypenred-1.15.2.0-cp312-cp312-macosx_14_0_x86_64.whl CPython 3.12 CPython 3.12 macOS 14.0+ x86-64 Details
pypenred-1.15.2.0-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details
pypenred-1.15.2.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pypenred-1.15.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
pypenred-1.15.2.0-cp311-cp311-macosx_14_0_x86_64.whl CPython 3.11 CPython 3.11 macOS 14.0+ x86-64 Details
pypenred-1.15.2.0-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details
pypenred-1.15.2.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
pypenred-1.15.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
pypenred-1.15.2.0-cp310-cp310-macosx_14_0_x86_64.whl CPython 3.10 CPython 3.10 macOS 14.0+ x86-64 Details
pypenred-1.15.2.0-cp310-cp310-macosx_14_0_arm64.whl CPython 3.10 CPython 3.10 macOS 14.0+ ARM64 Details

Total release size: 1.2 GB

Release files / pypenred-1.15.2.0-cp314-cp314-win_amd64.whl

Download URL pypenred-1.15.2.0-cp314-cp314-win_amd64.whl
Size 62.0 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
981867c40844a4b8883335195bfefdae154e5d8054ee51e361c78d6cbf77fd67
BLAKE2b-256 checksum
How to use checksums
fc43efb156e7f7696a086abf4cc40ff95b1ddec8252ae55ac46f7b71718a3cd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pypenred-1.15.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 62.7 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8adf8a68bace7513a383bb2a82f2ec21be21abe607e0e3b4a0e5373fd97d829e
BLAKE2b-256 checksum
How to use checksums
24b97fe17f279b50c5fd0d84a23d78282b276b4dd9f675a0c8c94d1bc36a7467
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp314-cp314-macosx_14_0_x86_64.whl

Download URL pypenred-1.15.2.0-cp314-cp314-macosx_14_0_x86_64.whl
Size 61.7 MB
Tags CPython 3.14 macOS 14.0+ x86-64
SHA-256 checksum
How to use checksums
9a3f7ce4178b30402de7f5112ecf78abf4288d0657394e9c580ed8bc2de517a4
BLAKE2b-256 checksum
How to use checksums
92f3a929e26bce66c81ee52680bde5ee2326cbe75a45a933c4f70206b58d7339
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp314-cp314-macosx_14_0_arm64.whl

Download URL pypenred-1.15.2.0-cp314-cp314-macosx_14_0_arm64.whl
Size 62.4 MB
Tags CPython 3.14 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
0b6ebbd6889cb39e3d65ec7328345f350b5b783cea1abe915bdf99b077861aa0
BLAKE2b-256 checksum
How to use checksums
8ba020cdfce2ddfc497e72add2d885c5ada9eb922a223471ccbe96dee718ef1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp313-cp313-win_amd64.whl

Download URL pypenred-1.15.2.0-cp313-cp313-win_amd64.whl
Size 60.5 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
b910ce71bf2c6af9f3c6d9b5a0800275032c3ea8e9ab2fedc865b9193af11046
BLAKE2b-256 checksum
How to use checksums
b3cd4a22019af3776c43c378265df2ea513e8ac6d702ac8bc864015c5a895173
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pypenred-1.15.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 62.7 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
48f40d5f09d880d684253e9d329c2a772fa3de7f2085421303f9aac25817b990
BLAKE2b-256 checksum
How to use checksums
b700ec75e55a04f149cc140ecf473eded60196aa1fc1254d68172b6ecc1cdba5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp313-cp313-macosx_14_0_x86_64.whl

Download URL pypenred-1.15.2.0-cp313-cp313-macosx_14_0_x86_64.whl
Size 61.7 MB
Tags CPython 3.13 macOS 14.0+ x86-64
SHA-256 checksum
How to use checksums
75b074b90e4cf4fe17900e0d564a8556d4034ce0c233db0f6b978bf99359ee72
BLAKE2b-256 checksum
How to use checksums
141a335d2ff285be347df9e7411e5d5b004d354bcadc663919870f1619b3abd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp313-cp313-macosx_14_0_arm64.whl

Download URL pypenred-1.15.2.0-cp313-cp313-macosx_14_0_arm64.whl
Size 62.4 MB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
d48f150a6de94d771ebf61507c6bdd3fc23e4241427f300ed7f66542e7147440
BLAKE2b-256 checksum
How to use checksums
54c6b6fdded47b310f272a451791be579dd62df108dfb7d4d9565a6d12e7be93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp312-cp312-win_amd64.whl

Download URL pypenred-1.15.2.0-cp312-cp312-win_amd64.whl
Size 60.5 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
ae9177e4efb4e24ea9799839e1e016b02689e7559b89ccdb66ff62b4d68ac94d
BLAKE2b-256 checksum
How to use checksums
976fb6a5c4844213bc8b2cb082a6f19e1db73f5ec1c88a8280931e279422757b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pypenred-1.15.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 62.7 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
0cbdb664e4ed6c84cad960c2265b8fb4a6b89eb49b385d19633d70d84ec1a9b0
BLAKE2b-256 checksum
How to use checksums
65eb6f70d87cfe6fb0973cb0ce54dfc8a9729f5fb6c0e1dae186e3b54b07e148
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp312-cp312-macosx_14_0_x86_64.whl

Download URL pypenred-1.15.2.0-cp312-cp312-macosx_14_0_x86_64.whl
Size 61.7 MB
Tags CPython 3.12 macOS 14.0+ x86-64
SHA-256 checksum
How to use checksums
9e816c9f251ba1ca4d4a41f8d0721ac5d61dff2c13adf38bc688f83de62b852b
BLAKE2b-256 checksum
How to use checksums
4f5d1fe341e2c2fd290f3b139d927e95d0ca112b8a014136acc1f5ae165b8ddc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp312-cp312-macosx_14_0_arm64.whl

Download URL pypenred-1.15.2.0-cp312-cp312-macosx_14_0_arm64.whl
Size 62.4 MB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
06fd6cb5f12b40be174803d9af94da14ae5ccf522e15519f95fbe58d441c40fa
BLAKE2b-256 checksum
How to use checksums
172830c139bafa774c90b4d164ac010565ce0ca7fb1655131e722b8c35932b01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp311-cp311-win_amd64.whl

Download URL pypenred-1.15.2.0-cp311-cp311-win_amd64.whl
Size 60.5 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
36a9769aea2c6608d5f973546e6a1f11680adad243ab69000f874b6eba609f43
BLAKE2b-256 checksum
How to use checksums
1d9b91263005c199981705fdf07b14e9fbf911c03111c5eca91b22931558c8b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pypenred-1.15.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 62.7 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
89d2f53490d05912ca7da320ad7387e9835052820082b891debc35b975e6d356
BLAKE2b-256 checksum
How to use checksums
379f005ad7407f30e9ee7735d5d2a5e0307443e9007804acd4ab72eb7bafdcbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp311-cp311-macosx_14_0_x86_64.whl

Download URL pypenred-1.15.2.0-cp311-cp311-macosx_14_0_x86_64.whl
Size 61.7 MB
Tags CPython 3.11 macOS 14.0+ x86-64
SHA-256 checksum
How to use checksums
e12d9b1fb345f0cc29761d661475052f333db83b8943b960bf417dd186ee0492
BLAKE2b-256 checksum
How to use checksums
73b1d8a05f4042e0cbbb0a8e2db997b7a6b1ba3e7246e3fd66ee2046719514c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp311-cp311-macosx_14_0_arm64.whl

Download URL pypenred-1.15.2.0-cp311-cp311-macosx_14_0_arm64.whl
Size 62.4 MB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
80295753ec577e6ce53d65acbfc6da69058ee99bae346276b02cad21d7753b0d
BLAKE2b-256 checksum
How to use checksums
f3cdaced77bc46d22b28d70bf2b129b20566133954414cb0c66622e304ac8645
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp310-cp310-win_amd64.whl

Download URL pypenred-1.15.2.0-cp310-cp310-win_amd64.whl
Size 60.5 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
4fc54bd0b119134cff6e2707e0b4196b36d7a825f7146f4a7a4d930177991aad
BLAKE2b-256 checksum
How to use checksums
7c6c283d0d473a9735a78677d804b5c32743dd971efbee7a3a7ba171811b3a4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pypenred-1.15.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 62.7 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
67b5787819244d5c6ea506e7016970586554438bdf526c76c5ac1c4e15620837
BLAKE2b-256 checksum
How to use checksums
efa873c06bea2229900f972ff10769be02a3468586bba10bc4001b7f8c23a43d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp310-cp310-macosx_14_0_x86_64.whl

Download URL pypenred-1.15.2.0-cp310-cp310-macosx_14_0_x86_64.whl
Size 61.7 MB
Tags CPython 3.10 macOS 14.0+ x86-64
SHA-256 checksum
How to use checksums
a28df76a370d0799bf7660cb2393ee8bc883b719ff1b0b758fe64df5467882b3
BLAKE2b-256 checksum
How to use checksums
25ca8a4e58255078528e16c40bd6276a2cdc330b25c1bff10e8b159f92052a0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pypenred-1.15.2.0-cp310-cp310-macosx_14_0_arm64.whl

Download URL pypenred-1.15.2.0-cp310-cp310-macosx_14_0_arm64.whl
Size 62.4 MB
Tags CPython 3.10 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
31b4da5552803e8915b6b554fb56e79fa29f14d49e20acc547941cfc1912d416
BLAKE2b-256 checksum
How to use checksums
21621d0bee58b77d4a0d76270275483eede65c92b444bdacac902512e28c4bb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

1.15.2.0 This release

20 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page