CouplingPhysicalModel¶
-
class
persalys.
CouplingPhysicalModel
(*args)¶ File-exchange based coupling model.
This model allows to wrap computer codes that read input values and write output values in text files. It is defined from a sequence steps, each step being defined from:
a list of input files to copy, or input files in which some variables are written
a command to launch the code
a list of output files and the associated output variables to read.
Each step is run sequentially in a temporary working directory for each input point. The name of the temporary working directory is computed from a hash of the input point.
- Parameters
- namestr
Model name
- inputssequence of
Input
Input variables (optional)
- outputssequence of
Output
Output variables (optional)
- stepssequence of
CouplingStep
List of steps to execute (optional)
Examples
>>> import persalys >>> import sys
input.txt is generated from the existing input_template.txt by replacing the @XN tokens:
>>> input_file = persalys.CouplingInputFile('/tmp/input_template.txt') >>> input_file.setConfiguredPath('input.txt') >>> input_file.setVariables(['X0', 'X1', 'X2'], ['@X0', '@X1', '@X2'], ['', '', ''])
external_program.py reads input.txt and writes output.txt:
>>> resource_file = persalys.CouplingResourceFile('external_program.py')
output variables Yj are read from output.txt and delimited by tokens, no token/line/column skipped:
>>> output_file = persalys.CouplingOutputFile('output.txt') >>> output_file.setVariables(['Y0', 'Y1'], ['Y0=', 'Y1='], [0, 0], [0, 0], [0, 0]) >>> step = persalys.CouplingStep(sys.executable + ' external_program.py input.txt', [input_file], [resource_file], [output_file]) >>> model = persalys.CouplingPhysicalModel('A', [step])
Methods
addInput
(self, input)Add an input variable.
addOutput
(self, output)Add an output variable.
clearInputs
(self)Remove all the input variables.
clearOutputs
(self)Remove all the output variables.
getCacheInputFile
(self)Cache input file accessor.
getCacheOutputFile
(self)Cache output file accessor.
getClassName
(self)Accessor to the object’s name.
getCleanupWorkDirectory
(self)Cleanup work directory accessor.
getCode
(self)Code accessor.
getCopula
(self)Copula accessor.
getDistribution
(self)Distribution accessor.
getFunction
(self, *args)Accessor to the underlying function.
getId
(self)Accessor to the object’s id.
getInputByName
(self, *args)Input variable accessor.
getInputDimension
(self)Number of input variables accessor.
getInputNames
(self)Input variable names accessor.
getInputRandomVector
(self)Input random vector accessor.
getInputs
(self)Input variables accessor.
getMeshModel
(self)Mesh model accessor.
getName
(self)Accessor to the object’s name.
getOutputByName
(self, *args)Output variable accessor.
getOutputDimension
(self)Number of output variables accessor.
getOutputNames
(self)Output variable names accessor.
getOutputRandomVector
(self, outputNames)Output random vector accessor.
getOutputs
(self)Output variables accessor.
getPointToFieldFunction
(self, *args)Accessor to the underlying function.
getProcessNumber
(self)Number of concurrent processes.
getPythonScript
(self)Python script accessor.
getRestrictedFunction
(self, *args)Accessor to the function restricted to its stochastic inputs.
getRestrictedPointToFieldFunction
(self, …)Accessor to the field function restricted to its stochastic inputs.
getSelectedOutputsNames
(self)Accessor to the selected outputs names.
getShadowedId
(self)Accessor to the object’s shadowed id.
getSteps
(self)Coupling steps accessor.
getStochasticInputNames
(self)Accessor to the names of the stochastic input variables.
getVisibility
(self)Accessor to the object’s visibility state.
hasInputNamed
(self, inputName)Check if an input has the given name.
hasMesh
(self)Whether the model has a mesh.
hasName
(self)Test if the object is named.
hasOutputNamed
(self, outputName)Check if an output has the given name.
hasStochasticInputs
(self)Whether it contains stochastic variables.
hasVisibleName
(self)Test if the object has a distinguishable name.
isParallel
(self)Whether the evaluations of the model are parallelized.
isValid
(self)Whether it is valid.
removeInput
(self, inputName)Remove an input variable.
removeOutput
(self, outputName)Remove an output variable.
selectOutput
(self, outputName, selected)Select output.
setCacheFiles
(self, inputFile, outputFile)Cache files accessor.
setCleanupWorkDirectory
(self, …)Cleanup work directory accessor.
setCode
(self, code)Code accessor.
setCopula
(self, inputNames, copula)Copula accessor.
setDistribution
(self, inputName, distribution)Input distribution accessor.
setDistributionParametersType
(self, …)Input distribution parameter type accessor.
setFiniteDifferenceStep
(self, inputName, step)Finite difference step accessor.
setInputDescription
(self, inputName, description)Input description accessor.
setInputName
(self, inputName, newName)Input variable name accessor.
setInputStochastic
(self, inputName, stoch)Whether the input variable is stochastic.
setInputValue
(self, inputName, value)Input variable value accessor.
setInputs
(self, inputs)Input variables accessor.
setMeshModel
(self, meshModel)Mesh model accessor.
setName
(self, name)Accessor to the object’s name.
setOutputDescription
(self, outputName, …)Output description accessor.
setOutputName
(self, outputName, newName)Output variable name accessor.
setOutputValue
(self, outputName, value)Output variable name accessor.
setOutputs
(self, outputs)Output variables accessor.
setParallel
(self, flag)Whether the evaluations of the model are parallelized.
setProcessNumber
(self, processNumber)Number of concurrent processes.
setShadowedId
(self, id)Accessor to the object’s shadowed id.
setSteps
(self, steps)Coupling steps accessor.
setVisibility
(self, visible)Accessor to the object’s visibility state.
getEvalTime
getWorkDir
setEvalTime
setWorkDir
updateCode
-
__init__
(self, *args)¶ Initialize self. See help(type(self)) for accurate signature.
-
clearInputs
(self)¶ Remove all the input variables.
-
clearOutputs
(self)¶ Remove all the output variables.
-
getCacheInputFile
(self)¶ Cache input file accessor.
- Returns
- input_filestr
Cache input file name.
-
getCacheOutputFile
(self)¶ Cache output file accessor.
- Returns
- output_filestr
Cache output file name.
-
getClassName
(self)¶ Accessor to the object’s name.
- Returns
- class_namestr
The object class name (object.__class__.__name__).
-
getCleanupWorkDirectory
(self)¶ Cleanup work directory accessor.
- Returns
- cleanup_work_dirbool
Whether the work directory is discarded
-
getCode
(self)¶ Code accessor.
- Returns
- codestr
Code text
-
getCopula
(self)¶ Copula accessor.
- Parameters
- copula
openturns.Copula
The copula
- copula
-
getDistribution
(self)¶ Distribution accessor.
- Parameters
- Distribution
openturns.ComposedDistribution
The composed distribution (marginals and dependence)
- Distribution
-
getFunction
(self, *args)¶ Accessor to the underlying function.
- Parameters
- outputNamessequence of str
Names of the outputs to be evaluated (optional)
- Returns
- function
openturns.Function
Function evaluating the outputs
- function
-
getId
(self)¶ Accessor to the object’s id.
- Returns
- idint
Internal unique identifier.
-
getInputByName
(self, *args)¶ Input variable accessor.
- Parameters
- namestr
Variable name
- Returns
- input
Input
Input variable
- input
-
getInputDimension
(self)¶ Number of input variables accessor.
- Returns
- dimensionint
Number of input variables
-
getInputNames
(self)¶ Input variable names accessor.
- Returns
- names
openturns.Description
Input variable names
- names
-
getInputRandomVector
(self)¶ Input random vector accessor.
- Returns
- names
openturns.RandomVector
Input random vector
- names
-
getName
(self)¶ Accessor to the object’s name.
- Returns
- namestr
The name of the object.
-
getOutputByName
(self, *args)¶ Output variable accessor.
- Parameters
- namestr
Variable name
- Returns
- input
Output
Output variable
- input
-
getOutputDimension
(self)¶ Number of output variables accessor.
- Returns
- dimensionint
Number of output variables
-
getOutputNames
(self)¶ Output variable names accessor.
- Returns
- names
openturns.Description
Ouput variable names
- names
-
getOutputRandomVector
(self, outputNames)¶ Output random vector accessor.
- Returns
- names
openturns.RandomVector
Output random vector
- names
-
getPointToFieldFunction
(self, *args)¶ Accessor to the underlying function.
- Parameters
- outputNamessequence of str
Names of the outputs to be evaluated (optional)
- Returns
- function
openturns.PointToFieldFunction
Function evaluating the outputs along the mesh nodes
- function
-
getProcessNumber
(self)¶ Number of concurrent processes.
- Returns
- process_numberint
Maximum number of processes
-
getPythonScript
(self)¶ Python script accessor.
- Returns
- scriptstr
Python script to replay the model
-
getRestrictedFunction
(self, *args)¶ Accessor to the function restricted to its stochastic inputs.
- Parameters
- outputNamessequence of str
Output variables (optional)
- Returns
- restricted
openturns.Function
Stochastic function
- restricted
-
getRestrictedPointToFieldFunction
(self, outputNames)¶ Accessor to the field function restricted to its stochastic inputs.
- Parameters
- outputNamessequence of str
Output variables (optional)
- Returns
- restricted
openturns.PointToFieldFunction
Stochastic field function (for model with mesh)
- restricted
-
getSelectedOutputsNames
(self)¶ Accessor to the selected outputs names.
- Returns
- names
openturns.Description
Selected outputs names
- names
-
getShadowedId
(self)¶ Accessor to the object’s shadowed id.
- Returns
- idint
Internal unique identifier.
-
getSteps
(self)¶ Coupling steps accessor.
- Returns
- stepssequence of
CouplingStep
List of steps to execute
- stepssequence of
-
getStochasticInputNames
(self)¶ Accessor to the names of the stochastic input variables.
- Returns
- names
openturns.Description
Names of the stochastic input variables
- names
-
getVisibility
(self)¶ Accessor to the object’s visibility state.
- Returns
- visiblebool
Visibility flag.
-
hasInputNamed
(self, inputName)¶ Check if an input has the given name.
- Parameters
- namestr
Variable name
- Returns
- hasbool
Whether an input has the given name
-
hasMesh
(self)¶ Whether the model has a mesh.
- Returns
- hasMeshbool
Whether the model has a mesh
-
hasName
(self)¶ Test if the object is named.
- Returns
- hasNamebool
True if the name is not empty.
-
hasOutputNamed
(self, outputName)¶ Check if an output has the given name.
- Parameters
- namestr
Variable name
- Returns
- hasbool
Whether an output has the given name
-
hasStochasticInputs
(self)¶ Whether it contains stochastic variables.
- Returns
- hasbool
Whether it contains stochastic variables
-
hasVisibleName
(self)¶ Test if the object has a distinguishable name.
- Returns
- hasVisibleNamebool
True if the name is not empty and not the default one.
-
isParallel
(self)¶ Whether the evaluations of the model are parallelized.
- Returns
- isParallelbool
Whether the evaluations of the model are parallelized (available only for the Python model)
-
isValid
(self)¶ Whether it is valid.
- Returns
- isValidbool
Whether it is valid
-
removeInput
(self, inputName)¶ Remove an input variable.
- Parameters
- namestr
Variable name
-
removeOutput
(self, outputName)¶ Remove an output variable.
- Parameters
- namestr
Variable name
-
selectOutput
(self, outputName, selected)¶ Select output.
- Parameters
- namestr
Output name
- isSelectedbool
Whether it is selected
-
setCacheFiles
(self, inputFile, outputFile)¶ Cache files accessor.
- Parameters
- input_filestr
Cache input file name.
- output_filestr
Cache output file name.
-
setCleanupWorkDirectory
(self, cleanupWorkDirectory)¶ Cleanup work directory accessor.
- Parameters
- cleanup_work_dirbool
Whether the work directory is discarded
-
setCode
(self, code)¶ Code accessor.
- Parameters
- codestr
Code text
-
setCopula
(self, inputNames, copula)¶ Copula accessor.
- Parameters
- copula
openturns.Copula
The copula
- copula
-
setDistribution
(self, inputName, distribution)¶ Input distribution accessor.
- Parameters
- namestr
Variable name
- distribution
openturns.Distribution
Variable distribution
-
setDistributionParametersType
(self, inputName, distributionParametersType)¶ Input distribution parameter type accessor.
- Parameters
- namestr
Variable name
- parametersTypeint
Distribution parameter type accessor
-
setFiniteDifferenceStep
(self, inputName, step)¶ Finite difference step accessor.
- Parameters
- namestr
Variable name
- stepfloat
Finite difference step used to define the gradient of the model’s function
-
setInputDescription
(self, inputName, description)¶ Input description accessor.
- Parameters
- namestr
Variable name
- descriptionstr
Description text
-
setInputName
(self, inputName, newName)¶ Input variable name accessor.
- Parameters
- namestr
Variable name
- newNamestr
New name
-
setInputStochastic
(self, inputName, stoch)¶ Whether the input variable is stochastic.
- Parameters
- namestr
Variable name
- isStochasticbool
Whether the input variable is stochastic
-
setInputValue
(self, inputName, value)¶ Input variable value accessor.
- Parameters
- namestr
Variable name
- valuefloat
New value
-
setInputs
(self, inputs)¶ Input variables accessor.
- Parameters
- inputssequence of
Input
Input variables
- inputssequence of
-
setName
(self, name)¶ Accessor to the object’s name.
- Parameters
- namestr
The name of the object.
-
setOutputDescription
(self, outputName, description)¶ Output description accessor.
- Parameters
- namestr
Variable name
- descriptionstr
Description text
-
setOutputName
(self, outputName, newName)¶ Output variable name accessor.
- Parameters
- namestr
Variable name
- newNamestr
New name
-
setOutputValue
(self, outputName, value)¶ Output variable name accessor.
- Parameters
- namestr
Variable name
- valuefloat
New value
-
setOutputs
(self, outputs)¶ Output variables accessor.
- Parameters
- outputssequence of
Output
Output variables
- outputssequence of
-
setParallel
(self, flag)¶ Whether the evaluations of the model are parallelized.
- Parameters
- isParallelbool
Whether the evaluations of the model are parallelized (available only for the Python model)
-
setProcessNumber
(self, processNumber)¶ Number of concurrent processes.
- Parameters
- process_numberint
Maximum number of processes
-
setShadowedId
(self, id)¶ Accessor to the object’s shadowed id.
- Parameters
- idint
Internal unique identifier.
-
setSteps
(self, steps)¶ Coupling steps accessor.
- Parameters
- stepssequence of
CouplingStep
List of steps to execute
- stepssequence of
-
setVisibility
(self, visible)¶ Accessor to the object’s visibility state.
- Parameters
- visiblebool
Visibility flag.