piglot.solver package

Subpackages

Submodules

piglot.solver.input_file_solver module

Module for input file-based solvers.

class DefaultInputDataGenerator(input_file: str, substitution_dependencies: List[str] | None = None, copy_dependencies: List[str] | None = None)[source]

Bases: InputDataGenerator

Default input data generator for input file-based solvers.

generate(parameters: ParameterSet, values: ndarray, tmp_dir: str) InputData[source]

Generate the input data for the given set of parameters.

Parameters

parametersParameterSet

Parameter set for this problem.

valuesnp.ndarray

Current parameters to evaluate.

tmp_dirstr

Temporary directory to run the problem.

Returns

InputData

Input data for this problem.

class InputData(tmp_dir: str, input_file: str, dependencies: List[str])[source]

Bases: object

Class for input file-based input data.

class InputDataGenerator[source]

Bases: ABC

Base class for input data generators for input file-based solvers.

abstract generate(parameters: ParameterSet, values: ndarray, tmp_dir: str) InputData[source]

Generate the input data for the given set of parameters.

Parameters

parametersParameterSet

Parameter set for this problem.

valuesnp.ndarray

Current parameters to evaluate.

tmp_dirstr

Temporary directory to run the problem.

class InputFileCase(name: str, fields: Dict[str, OutputField], generator: InputDataGenerator)[source]

Bases: Case, ABC

Base case class for input file-based solvers.

classmethod get_dependencies(input_file: str) Tuple[List[str], List[str]][source]

Get the dependencies for a given input file.

Override this method to provide custom dependencies.

Parameters

input_filestr

Input file to check for dependencies.

Returns

Tuple[List[str], List[str]]

Substitution and copy dependencies for this input file.

get_fields() List[str][source]

Get the fields to output for this case.

Returns

List[str]

Fields to output for this case.

abstract classmethod get_supported_fields() Dict[str, Type[OutputField]][source]

Get the supported fields for this input file type.

Returns

Dict[str, Type[OutputField]]

Names and supported fields for this input file type.

name() str[source]

Return the name of the case.

Returns

str

Name of the case.

classmethod read(name: str, config: Dict[str, Any]) V[source]

Read the case from the configuration dictionary.

Parameters

namestr

Name of the case.

configDict[str, Any]

Configuration dictionary.

Returns

InputFileCase

Case to use for this problem.

run(parameters: ParameterSet, values: ndarray, tmp_dir: str) CaseResult[source]

Run the case for the given set of parameters.

Parameters

parametersParameterSet

Parameter set for this problem.

valuesnp.ndarray

Current parameters to evaluate.

tmp_dirstr

Temporary directory to run the problem.

Returns

CaseResult

Result of the case.

class InputFileSolver(cases: List[Case], parameters: ParameterSet, output_dir: str, tmp_dir: str, verbosity: str, parallel: int = 1)[source]

Bases: MultiCaseSolver

Base class for input file-based solvers.

abstract classmethod get_case_class() Type[InputFileCase][source]

Get the case class to use for this solver.

Returns

Type[InputFileCase]

InputFileCase class to use for this solver.

class OutputField[source]

Bases: ABC

Generic class for output fields.

abstract check(input_data: InputData) None[source]

Check for validity in the input data before reading.

Parameters

input_dataInputData

Input data to check for.

abstract get(input_data: InputData) OutputResult[source]

Read the output data from the simulation.

Parameters

input_dataInputData

Input data to check for.

Returns

OutputResult

Output result for this field.

abstract classmethod read(config: Dict[str, Any]) T[source]

Read the output field from the configuration dictionary.

Parameters

configDict[str, Any]

Configuration dictionary.

Returns

OutputField

Output field to use for this problem.

class ScriptOutputField[source]

Bases: OutputField

Class for script-bsaed output fields.

check(input_data: InputData) None[source]

Check for validity in the input data before reading.

Parameters

input_dataInputData

Input data to check for.

static read(config: Dict[str, Any]) ScriptOutputField[source]

Read the output field from the configuration dictionary.

Parameters

configDict[str, Any]

Configuration dictionary.

Returns

ScriptOutputField

Output field to use for this problem.

write_parameters(param_value: ~typing.Dict[str, float], source: str, dest: str, regex: ~typing.Callable[[str], str] = <function <lambda>>) None[source]

Write the set of parameters to the input file.

Parameters

param_valueDict[str, float]

Collection of parameters and their values.

sourcestr

Source input file, to be copied to the destination.

deststr

Destination input file.

regexCallable[[str], str], optional

Function to generate the regex for the parameter substitution. By default, uses the regex to replace “<param_name>” with the value.

piglot.solver.multi_case_solver module

Module for multi-case solvers.

class Case[source]

Bases: ABC

Base case class for multi-case solvers.

abstract get_fields() List[str][source]

Get the fields to output for this case.

Returns

List[str]

Fields to output for this case.

abstract name() str[source]

Return the name of the case.

Returns

str

Name of the case.

abstract classmethod read(name: str, config: Dict[str, Any]) T[source]

Read the case from the configuration dictionary.

Parameters

namestr

Name of the case.

configDict[str, Any]

Configuration dictionary.

Returns

Case

Case to use for this problem.

abstract run(parameters: ParameterSet, values: ndarray, tmp_dir: str) CaseResult[source]

Run the case for the given set of parameters.

Parameters

parametersParameterSet

Parameter set for this problem.

valuesnp.ndarray

Current parameters to evaluate.

tmp_dirstr

Temporary directory to run the problem.

Returns

CaseResult

Result of the case.

class MultiCaseSolver(cases: List[Case], parameters: ParameterSet, output_dir: str, tmp_dir: str, verbosity: str, parallel: int = 1)[source]

Bases: Solver, ABC

Base class for solvers with multiple cases.

abstract classmethod get_case_class() Type[Case][source]

Get the case class to use for this solver.

Returns

Type[Case]

Case class to use for this solver.

get_case_params(param_hash: str) Dict[str, float][source]

Get the parameters for a given hash.

Parameters

param_hashstr

Hash of the case to load.

Returns

Dict[str, float]

Parameters for this hash.

get_case_results(param_hash: str) List[CaseResult][source]

Get the results for all cases for a given hash.

Parameters

param_hashstr

Hash of the case to load.

Returns

List[CaseResult]

Results for all cases.

get_output_fields() List[str][source]

Get all output fields.

Returns

List[str]

Output fields.

get_output_response(param_hash: str) Dict[str, OutputResult][source]

Get the responses from all output fields for a given case.

Parameters

param_hashstr

Hash of the case to load.

Returns

Dict[str, OutputResult]

Output responses.

prepare() None[source]

Prepare data for the optimisation.

classmethod read(config: Dict[str, Any], parameters: ParameterSet, output_dir: str) T[source]

Read the solver from the configuration dictionary.

Parameters

configDict[str, Any]

Configuration dictionary.

parametersParameterSet

Parameter set for this problem.

output_dirstr

Path to the output directory.

Returns

T

Solver to use for this problem.

solve(values: ndarray, concurrent: bool) Dict[str, OutputResult][source]

Solve all cases for the given set of parameter values.

Parameters

valuesarray

Current parameters to evaluate.

concurrentbool

Whether this run may be concurrent to another one (so use unique file names).

Returns

Dict[str, OutputResult]

Evaluated results for each output field.

piglot.solver.script_solver module

Module for script-based solvers.

class ScriptSolver(script: ScriptSolverCallable, parameters: ParameterSet, output_dir: str, tmp_dir: str, verbosity: str)[source]

Bases: SingleCaseSolver

Script-based solvers.

classmethod read(config: Dict[str, Any], parameters: ParameterSet, output_dir: str) ScriptSolver[source]

Read the solver from the configuration dictionary.

Parameters

configDict[str, Any]

Configuration dictionary.

parametersParameterSet

Parameter set for this problem.

output_dirstr

Path to the output directory.

Returns

ScriptSolver

Solver to use for this problem.

class ScriptSolverCallable[source]

Bases: ABC

Interface for script-based solvers.

abstract static get_output_fields() List[str][source]

Get the output fields for this solver.

Returns

List[str]

Output fields for this solver.

abstract static solve(values: Dict[str, float]) Dict[str, OutputResult][source]

Callable for script-based solvers.

Parameters

valuesDict[str, float]

Current parameters to evaluate.

Returns

Dict[str, OutputResult]

Evaluated results for each output field.

piglot.solver.solver module

Module for solvers.

class CaseResult(begin_time: float, run_time: float, values: ndarray, success: bool, param_hash: str, responses: Dict[str, OutputResult])[source]

Bases: object

Class for case results.

begin_time: float
param_hash: str
static read(filename: str, parameters: ParameterSet) CaseResult[source]

Read a case result file.

Parameters

filenamestr

Path to the case result file.

parametersParameterSet

Set of parameters for this case.

Returns

CaseResult

Result instance.

responses: Dict[str, OutputResult]
run_time: float
success: bool
values: ndarray
write(filename: str, parameters: ParameterSet) None[source]

Write out the case result.

Parameters

filenamestr

Path to write the file to.

parametersParameterSet

Set of parameters for this case.

class OutputResult(time: ndarray, data: ndarray)[source]

Bases: object

Container for output results.

data: ndarray
get_data() ndarray[source]

Get the data column of the result.

Returns

np.ndarray

Data column.

get_time() ndarray[source]

Get the time column of the result.

Returns

np.ndarray

Time column.

time: ndarray
class SingleCaseSolver(output_fields: List[str], parameters: ParameterSet, output_dir: str, tmp_dir: str, verbosity: str)[source]

Bases: Solver, ABC

Generic class for solvers with a single case.

get_case_params(param_hash: str) Dict[str, float][source]

Get the parameters for a given hash.

Parameters

param_hashstr

Hash of the case to load.

Returns

Dict[str, float]

Parameters for this hash.

get_case_result(param_hash: str) CaseResult[source]

Get the result for a given case.

Parameters

param_hashstr

Hash of the case to load.

Returns

CaseResult

Result for this hash.

get_output_fields() List[str][source]

Get all output fields.

Returns

List[str]

Output fields.

get_output_response(param_hash: str) Dict[str, OutputResult][source]

Get the responses from all output fields for a given case.

Parameters

param_hashstr

Hash of the case to load.

Returns

Dict[str, OutputResult]

Output responses.

prepare() None[source]

Prepare data for the optimisation.

solve(values: ndarray, concurrent: bool) Dict[str, OutputResult][source]

Solve all cases for the given set of parameter values.

Parameters

valuesarray

Current parameters to evaluate.

concurrentbool

Whether this run may be concurrent to another one (so use unique file names).

Returns

Dict[str, OutputResult]

Evaluated results for each output field.

class Solver(parameters: ParameterSet, output_dir: str, tmp_dir: str, verbosity: str)[source]

Bases: ABC

Base class for solvers.

abstract get_case_params(param_hash: str) Dict[str, float][source]

Get the parameters for a given hash.

Parameters

param_hashstr

Hash of the case to load.

Returns

Dict[str, float]

Parameters for this hash.

get_current_response() Dict[str, OutputResult][source]

Get the responses from a given output field for all cases.

Returns

Dict[str, OutputResult]

Output responses.

abstract get_output_fields() List[str][source]

Get all output fields.

Returns

List[str]

Output fields.

abstract get_output_response(param_hash: str) Dict[str, OutputResult][source]

Get the responses from all output fields for a given case.

Parameters

param_hashstr

Hash of the case to load.

Returns

Dict[str, OutputResult]

Output responses.

abstract prepare() None[source]

Prepare data for the optimisation.

abstract classmethod read(config: Dict[str, Any], parameters: ParameterSet, output_dir: str) T[source]

Read the solver from the configuration dictionary.

Parameters

configDict[str, Any]

Configuration dictionary.

parametersParameterSet

Parameter set for this problem.

output_dirstr

Path to the output directory.

Returns

Solver

Solver to use for this problem.

abstract solve(values: ndarray, concurrent: bool) Dict[str, OutputResult][source]

Solve all cases for the given set of parameter values.

Parameters

valuesarray

Current parameters to evaluate.

concurrentbool

Whether this run may be concurrent to another one (so use unique file names).

Returns

Dict[str, OutputResult]

Evaluated results for each output field.

Module contents

Interface for solvers.

read_solver(config: Dict[str, Any], parameters: ParameterSet, output_dir: str) Solver[source]

Read the solver from the configuration dictionary.

Parameters

configDict[str, Any]

Configuration dictionary.

parametersParameterSet

Parameter set for this problem.

output_dirstr

Path to the output directory.

Returns

Solver

Solver to use for this problem.