gemseo / problems / scalable / linear

Show inherited members

linear_discipline module

Dummy linear discipline.

class gemseo.problems.scalable.linear.linear_discipline.LinearDiscipline(name, input_names, output_names, inputs_size=1, outputs_size=1, grammar_type=GrammarType.JSON, matrix_format=MatrixFormat.DENSE, matrix_density=0.1)[source]

Bases: MDODiscipline

A discipline that computes random outputs from inputs.

The output are computed by a product with a random matrix and the inputs. The inputs and outputs names are specified by the user. The size of inputs and outputs can be specified.

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • name (str) – The discipline name.

  • input_names (Sequence[str]) – The input data names.

  • output_names (Sequence[str]) – The output data names.

  • inputs_size (int) –

    The size of input data vectors, each input data is of shape (inputs_size,).

    By default it is set to 1.

  • outputs_size (int) –

    The size of output data vectors, each output data is of shape (outputs_size,).

    By default it is set to 1.

  • grammar_type (MDODiscipline.GrammarType) –

    The type of grammars.

    By default it is set to “JSONGrammar”.

  • matrix_format (MatrixFormat) –

    The format of the Jacobian matrix.

    By default it is set to “dense”.

  • matrix_density (float) –

    The percentage of non-zero elements when the matrix is sparse.

    By default it is set to 0.1.

Raises:

ValueError – if input_names or output_names are empty.

class MatrixFormat(value)[source]

Bases: str, Enum

The format of the Jacobian matrix.

DENSE corresponds to numpy.ndarray. CSC, CSR, LIL and DOK correspond to sparse format from scipy.sparse.

CSC = 'csc'
CSR = 'csr'
DENSE = 'dense'
DOK = 'dok'
LIL = 'lil'
DEFAULT_MATRIX_DENSITY: ClassVar[float] = 0.1
cache: AbstractCache | None

The cache containing one or several executions of the discipline according to the cache policy.

data_processor: DataProcessor

A tool to pre- and post-process discipline data.

exec_for_lin: bool

Whether the last execution was due to a linearization.

input_grammar: BaseGrammar

The input grammar.

jac: dict[str, dict[str, ndarray]]

The Jacobians of the outputs wrt inputs.

The structure is {output: {input: matrix}}.

name: str

The name of the discipline.

output_grammar: BaseGrammar

The output grammar.

re_exec_policy: ReExecutionPolicy

The policy to re-execute the same discipline.

residual_variables: Mapping[str, str]

The output variables mapping to their inputs, to be considered as residuals; they shall be equal to zero.

run_solves_residuals: bool

Whether the run method shall solve the residuals.

gemseo.problems.scalable.linear.linear_discipline.rand(d0, d1, ..., dn)

Random values in a given shape.

Note

This is a convenience function for users porting code from Matlab, and wraps random_sample. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.

Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

Parameters:
  • d0 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • d1 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • ... (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • dn (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

Returns:

out – Random values.

Return type:

ndarray, shape (d0, d1, ..., dn)

See also

random

Examples

>>> np.random.rand(3,2)
array([[ 0.14022471,  0.96360618],  #random
       [ 0.37601032,  0.25528411],  #random
       [ 0.49313049,  0.94909878]]) #random