Simulation Module

penred simulation module

pyPenred.simulation.configFile2YAML(arg0: str) str

Reads a configuration file and returns a YAML string with the read information.

Parameters:

filename (str) – File to be read.

Returns:

String containing the information in YAML format

pyPenred.simulation.create

alias of simulator

pyPenred.simulation.dict2SectionString(conf: dict) str

Converts a dictionary to a compatible penRed configuration section string.

Parameters:

conf (dict) – configuration dictionary to be converted.

Returns:

String containing the converted dictionary

pyPenred.simulation.errorMessage(code: SupportsInt) str

Produces the error message associated to the specified error code.

Parameters:

code (int) – Error code.

Returns:

String containing the error message

pyPenred.simulation.setConfigurationLog(filename: str) None

Specify the file where the configuraiton logs will be redirected.

Parameters:

filename (str) – Configuration log file name.

Returns:

None

pyPenred.simulation.setSimulationLog(filename: str) None

Specify the file where the simulation logs will be redirected.

Parameters:

filename (str) – Simulation log file name.

Returns:

None

class pyPenred.simulation.simulator

Bases: pybind11_object

A simulator class for penRed simulations.

This class handles particle transport and interaction modeling in the penRed framework. It provides methods to configure and run simulations, track particles, and retrieve results.

__init__(self: simulator) None
configContext(self: simulator, config: dict) None

Saves the context configuration from the provided dictionary.

Parameters:

config (dict) – Dictionary with the context configuration.

Returns:

None

Raises:

ValueError – If configuraiton set fails.

configFromFile(self: simulator, filename: str) None

Sets the entire configuration from a file matching the penRed internal data format.

Parameters:

filename (str) – Configuration file.

Returns:

None

Raises:

ValueError – If file parsing fails.

configFromString(self: simulator, config: str) None

Sets the entire configuration from a string matching the penRed internal data format.

Parameters:

config (str) – Text containing the configuration.

Returns:

None

Raises:

ValueError – If file parsing fails.

configGeometry(self: simulator, config: dict) None

Saves the geometry configuration from the provided dictionary.

Parameters:

config (dict) – Dictionary with the geometry configuration.

Returns:

None

Raises:

ValueError – If configuraiton set fails.

configSource(self: simulator, config: dict) None

Saves the particle sources configuration from the provided dictionary.

Parameters:

config (dict) – Dictionary with the source configuration.

Returns:

None

Raises:

ValueError – If configuraiton set fails.

configTally(self: simulator, config: dict) None

Saves the tallies configuration from the provided dictionary.

Parameters:

config (dict) – Dictionary with the tallies configuration.

Returns:

None

Raises:

ValueError – If configuraiton set fails.

configVR(self: simulator, config: dict) None

Saves the variance reduction configuration from the provided dictionary.

Parameters:

config (dict) – Dictionary with the variance reduction configuration.

Returns:

None

Raises:

ValueError – If configuraiton set fails.

configure(self: simulator, config: dict) None

Saves the entire simulation configuration from the provided dictionary.

Parameters:

config (dict) – Dictionary with the simulation configuration.

Returns:

None

Raises:

ValueError – If configuraiton set fails.

forceFinish(self: simulator) None

Forces the simulation finish reducing the number of histories to be simulated. Finishing a simulation can take some time due tally postprocessing.

Parameters:

None

Returns:

None

isSimulating(self: simulator) bool

Checks if a simulation is running.

Parameters:

None

Returns:

True if a simulation is running, false otherwise.

Return type:

Bool

setSimConfig(self: simulator, config: dict) None

Saves the simulation parameters from the provided dictionary.

Parameters:

config (dict) – Dictionary with the variance simulation configuration.

Returns:

None

Raises:

ValueError – If configuraiton set fails.

simSpeeds(self: simulator) tuple

If a simulation is running, returns the simulation speeds, in histories per second, for each used thread

Parameters:

None

Returns:

A tuple containing the simulation speed of each thead

Return type:

tuple

simulate(self: pyPenred.simulation.simulator, async: bool = False) None

Executes the configured simulation in either blocking or non-blocking mode.

Parameters:

async (bool, optional) – Simulation execution mode. - False (default): Blocking mode (waits for completion) - True: Non-blocking mode (returns immediately)

Returns:

None

Raises:

ValueError – If invalid configurations are detected pre-simulation.

Example

#!/usr/bin/env python3
import pyPenred
import time

#Define configuration file
configFile = "config.in"

#Create simulation object
simu = pyPenred.simulation.create()

#Try to configure the simulation from the configuration file
simu.configFromFile(configFile)

print("Configuration set\n")

#Start the simulation asynchronously
simu.simulate(True)

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

print("Simulation finished")
simulated(self: simulator) tuple

If a simulation is running, returns the simulated histories for each thread at the current source.

Parameters:

None

Returns:

A tuple with the the pairs (simulated, to simulate) histories for each thread at the current source

Return type:

tuple

stringifyStatus(self: simulator) tuple

If a simulation is running, returns a tuple with the stringified simulation status of each thread

Parameters:

None

Returns:

A tuple with a string for each thread describing its status.

Return type:

tuple