gemseo / problems / scalable / linear

# disciplines_generator module¶

## Dummy linear discipline generator¶

A utility that generates dummy disciplines from a specification. The inputs and output names are specified by the user. A linear random dependency between the inputs and outputs is created. The size of the inputs and outputs can be parametrized by the user. The MDA of the generated disciplines will always converge because all the outputs are in [0, 1] if the inputs are in [0, 1]. The analytic Jacobian is provided.

gemseo.problems.scalable.linear.disciplines_generator.create_disciplines_from_desc(disc_descriptions, inputs_size=1, outputs_size=1, grammar_type='JSONGrammar')[source]

Generate LinearDiscipline classes according to a specification.

The specification is as follows:

[
("Disc_name1", ["in1"], ["out1", "out2"]),
("Disc_name2", ["in2", "out1"], ["out3", "out2"]),
]

This will generate two disciplines:
• One named “Disc_name1” with the inputs [“in1”] and the outputs [“out1”, “out2”].

• Another named “Disc_name2” with the inputs [“in2”, “out1”] and the outputs [“out3”, “out2”].

Parameters:
• disc_descriptions – The specification of the disciplines, each item is (name, inputs_names, outputs_names), disciplines names may be non-unique.

• inputs_size (int) –

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

By default it is set to 1.

• outputs_size (int) –

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

By default it is set to 1.

• grammar_type (str) –

The type of grammars used by the disciplines.

By default it is set to “JSONGrammar”.

Returns:
Return type:
gemseo.problems.scalable.linear.disciplines_generator.create_disciplines_from_sizes(nb_of_disc, nb_of_total_disc_io, nb_of_disc_inputs=1, nb_of_disc_outputs=1, inputs_size=1, outputs_size=1, grammar_type='JSONGrammar', unique_disc_per_output=False, no_self_coupled=False, no_strong_couplings=False)[source]

Generate a LinearDiscipline according to a specification.

The names of the disciplines will be automatic combinations of capital letters. The names of the inputs and outputs are generated from string representations of integers.

Parameters:
• nb_of_disc (int) – The total number of disciplines.

• nb_of_total_disc_io (int) – The total number of input and output data names in the overall process.

• nb_of_disc_inputs (int) –

The number of disciplines inputs, same for all disciplines.

By default it is set to 1.

• nb_of_disc_outputs (int) –

The number of disciplines outputs, same for all disciplines.

By default it is set to 1.

• inputs_size (int) –

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

By default it is set to 1.

• outputs_size (int) –

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

By default it is set to 1.

• grammar_type (str) –

The type of grammars used by the discipline.

By default it is set to “JSONGrammar”.

• unique_disc_per_output

Whether to ensure that the outputs are computed by at most one discipline.

By default it is set to False.

• no_self_coupled

Whether to ensure that no discipline has an output that is also an input.

By default it is set to False.

• no_strong_couplings

Whether to ensure that there is no strong couplings in the problem.

By default it is set to False.

Returns:
Raises:

ValueError – If the number of disciplines is inconsistent with the total number of inputs or outputs.

Return type:
gemseo.problems.scalable.linear.disciplines_generator.shuffle(x)

Modify a sequence in-place by shuffling its contents.

This function only shuffles the array along the first axis of a multi-dimensional array. The order of sub-arrays is changed but their contents remains the same.

Note

New code should use the shuffle method of a default_rng() instance instead; please see the Quick Start.

Parameters:

x (ndarray or MutableSequence) – The array, list or mutable sequence to be shuffled.

Return type:

None

random.Generator.shuffle

which should be used for new code.

Examples

>>> arr = np.arange(10)
>>> np.random.shuffle(arr)
>>> arr
[1 7 5 2 9 4 3 6 0 8] # random


Multi-dimensional arrays are only shuffled along the first axis:

>>> arr = np.arange(9).reshape((3, 3))
>>> np.random.shuffle(arr)
>>> arr
array([[3, 4, 5], # random
[6, 7, 8],
[0, 1, 2]])