pyPENELOPE

runner – Base runner classes

Inheritance diagram of penelopetools.api.runner

exception penelopetools.api.runner.InvalidOptions

Bases: exceptions.Exception

Exception raised when an invalid options for the specified runner is passed.

class penelopetools.api.runner.Runner(program, material_program, options=None, results_dir=None)

Bases: threading.Thread, misctools.hook.Hookable

Runner of a PENELOPE simulation. The method run build the input file(s) and the material file(s) based on the options. It then starts the simulation. The results are saved in the current folder or in the specified results directory. The class is derived from threading.Thread so it can be run in a thread.

Parameters:
  • program (_Program) – program to be executed to run the simulation
  • material_program (_Material) – program to be used to create the material file(s)
  • options (Options) – options of the simulation to be executed. The options are optional since they can be specified later via the attribute options
  • results_dir – directory where to save the results of the simulation. If it is not specified, the current directory is used.
create()

Creates all simulation files with the defined options, without starting the simulation. The simulation files are saved in the results directory.

input_filepath

Filepath to the IN file. Raises a ValueError if the work path is not defined.

material_program

Program to create the material file(s).

options

Options of the simulation. The name of the thread is automatically set as the title of the simulation in the options.

program

Program to execute the simulation.

results_dir

Results directory. The directory must a valid path.

resume()

Resumes a simulation that was stopped. The simulation files must be placed in the specified results directory.

run()

Executes the simulation. This is an internal method. The method start or resume should be called to start or resume a simulation.

start()

Starts the simulation with the defined options.

The input file, the material file(s) and the geometry file are automatically created in the work directory. The method run is called and the simulation is started in a thread. When the simulation is completed, the results are copied into the results directory.

stop()

Stops the execution of a simulation.

use_results_dir_as_work_dir()

Sets the work path to be the same as the base results path.

work_dir

Directory where the files are saved during the simulation. The directory must a valid path. If the attribute is deleted, the files are saved in a temporary folder during the simulation.

class penelopetools.api.runner.RunnerQueue(maxsize, program, material_program)

Bases: Queue.Queue

Queue to run several simulations in different threads. The simulations must all have the same type of options and be run with the same program.

To put a simulation in the queue, the method put must be called with one tuple as argument. The tuple contains two items:

  • the options of the simulation (_Options)
  • the results directory for the simulation

The method join can be called to wait for all the simulations to finish.

Parameters:
  • maxsize (int) – maximum number of simulation running simultaneously
  • program (_Program) – program to be executed to run the simulations
  • material_program (_Material) – program to be used to create the material file(s)

Examples:

>>> queue = RunnerQueue(2, program, material_program)
>>> queue.put((options1, resultsdir1))
>>> queue.put((options1, resultsdir1))
>>> queue.join()
stop()

Stops all the simulations in the queue.