cosapp.drivers.utils

Functions

dealias_problem(problem[, name])

Resolve unknown aliasing in problem due to pulling connectors (if any) in context system.

Classes

Constraint(lhs, rhs[, is_inequality])

Named tuple representing a non-negative constraint of the kind lhs <op> rhs, where <op> is either == (equality) or >= (inequality constraint), depending on Boolean attribute is_inequality.

ConstraintParser()

ConstraintType(value[, names, module, ...])

Enum covering constraint types

DesignProblemHandler([system])

Class managing tied design and off-design problems, including unknown aliasing.

SystemAnalyzer([system])

Class containing data collected on a system, to be shared between different drivers.

class cosapp.drivers.utils.Constraint(lhs: str, rhs: str, is_inequality: bool = True)[source]

Bases: NamedTuple

Named tuple representing a non-negative constraint of the kind lhs <op> rhs, where <op> is either == (equality) or >= (inequality constraint), depending on Boolean attribute is_inequality.

Attributes:

  • lhs [str]: left-hand side.

  • rhs [str]: right-hand side.

  • is_inequality [bool].

Properties:

  • expression [str]: non-negative constraint lhs - rhs.

property expression: str
is_inequality: bool

Alias for field number 2

lhs: str

Alias for field number 0

rhs: str

Alias for field number 1

class cosapp.drivers.utils.ConstraintParser[source]

Bases: object

classmethod parse(expression: str | List[str]) Set[Constraint][source]

Parse a string expression or a list thereof as a set of non-negative constraints to be used in solvers.

Parameters:

  • expression [str or List[str]]:

    Human-readable equality or inequality constraints, such as ‘x >= y’, ‘0 < alpha < 1’, or a list thereof.

Returns:

  • constraints [Set[Constraint]]:

    Set of Constraint named tuple objects.

classmethod types() Dict[str, ConstraintType][source]
class cosapp.drivers.utils.ConstraintType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum covering constraint types

EQ = {'operator': '==', 'sort': <function ConstraintType.<lambda>>}
GE = {'operator': '>=', 'sort': <function ConstraintType.<lambda>>}
LE = {'operator': '<=', 'sort': <function ConstraintType.<lambda>>}
property description: str
expression(lhs: str, rhs: str) str[source]
property is_inequality: bool
property operator: str
sort(lhs: str, rhs: str) Tuple[str, str][source]
class cosapp.drivers.utils.DesignProblemHandler(system: 'cosapp.systems.System' | None = None)[source]

Bases: SystemAnalyzer

Class managing tied design and off-design problems, including unknown aliasing.

check_context(design: MathematicalProblem, offdesign: MathematicalProblem) None[source]
clear() None[source]

Reset inner problems

copy(prune=True) DesignProblemHandler[source]

Returns a copy of the current object.

Parameters:

  • prune, Optional[bool]:

    If True (default), resolve unknown aliasing first. If False, returned handler contains copies of object problems.

copy_problems(prune=True) Tuple[MathematicalProblem, MathematicalProblem][source]

Export design and off-design problems.

Parameters:

  • prune, Optional[bool]:

    If True (default), resolve unknown aliasing first. If False, returned problems are copies of object attributes.

Results:

  • (design, offdesign): Copies of design and off-design problems,

    as a tuple of MathematicalProblem objects.

extend(other: DesignProblemHandler, prune=True, copy=True, overwrite=False) DesignProblemHandler[source]

Extend both design and off-design problems from other handler.

Parameters:
  • [bool (- overwrite) – If True (default), added problems are pruned before being added.

  • optional] – If True (default), added problems are pruned before being added.

  • [bool – Determines whether problem copies should be made before extension.

  • optional] – Determines whether problem copies should be made before extension.

  • [bool – Overwrite option, forwarded to MathematicalProblem.extend.

  • optional] – Overwrite option, forwarded to MathematicalProblem.extend.

classmethod make(design: MathematicalProblem, offdesign: MathematicalProblem) DesignProblemHandler[source]
merged_problem(name='merged', offdesign_prefix='offdesign', copy=True) MathematicalProblem[source]

Merge design and off-design problems into a single MathematicalProblem instance.

Parameters:
  • [str (- offdesign_prefix) – Merged problem name (default: ‘merged’).

  • optional] – Merged problem name (default: ‘merged’).

  • [str – If not empty or None, applies a prefix to dict keys in off-design unknowns and equations.

  • optional] – If not empty or None, applies a prefix to dict keys in off-design unknowns and equations.

  • [bool (- copy) – Perform copies if True (default).

  • optional] – Perform copies if True (default).

new_problem(name: str) MathematicalProblem[source]

Create new MathematicalProblem instance

property problems: Tuple[MathematicalProblem, MathematicalProblem]

design and off-design problems as a tuple

Type:

Tuple[MathematicalProblem, MathematicalProblem]

prune() None[source]

Remove connected unknowns and resolve unknown aliasing in design and off-desing problems.

class cosapp.drivers.utils.SystemAnalyzer(system: 'cosapp.systems.System' | None = None)[source]

Bases: object

Class containing data collected on a system, to be shared between different drivers.

check_system() None[source]

Check that object is associated to a system.

Raises:

ValueError

clear() None[source]

Hook function to clear internal data, if any. Called at object instanciation.

property system: cosapp.systems.System

system of interest

Type:

System

cosapp.drivers.utils.dealias_problem(problem: MathematicalProblem, name=None) MathematicalProblem[source]

Resolve unknown aliasing in problem due to pulling connectors (if any) in context system.

Parameters:

  • problem [MathematicalProblem]:

    Mathematical problem to be de-aliased.

  • name [str, optional]:

    Name of output MathematicalProblem object.

Returns:

MathematicalProblem:

New mathematical problem, with identical equations as source problem, but de-aliased unknowns.