Skip to content
Get started

eqiora.lang

← Python API index

Author Eqiora Modules, Components, expressions, and equations in Python.

View source
python
import eqiora
from eqiora import lang as q
source = eqiora.Module("example")
component = source.model("Balance")
x = component.field("x", value_type=eqiora.ValueType.real(),
role=eqiora.FieldRole.Variable)
component.relation("balance", q.equation(x, 2))
print(source.to_eqi())
model = eqiora.compile(source=source)

to_eqi() prints the generated source: a model with the relation x = 2. Compiling the Module goes through the same compiler as a handwritten .eqi file. Add every declaration before calling to_eqi() or compile. See modeling for parameters, components, imports, and spatial equations.

Algebraic trace of a finite endomorphism or spatial tensor.

python
def matrix_trace(value: object) -> Expression: ...

Determinant of a real finite endomorphism.

python
def determinant(value: object) -> Expression: ...

Inverse of a finite map; execution fails if the map is singular or cannot be inverted reliably.

python
def inverse(value: object) -> Expression: ...

Transpose (algebraic dual), without complex conjugation.

python
def transpose(value: object) -> Expression: ...

Conjugate transpose in the declared orthonormal finite bases.

python
def adjoint(value: object) -> Expression: ...

Apply a map to coordinates in its input basis.

python
def apply(left: object, right: object) -> Expression: ...

Compose two maps, left after right. The output space of right must be the input space of left.

python
def compose(left: object, right: object) -> Expression: ...

Bilinearly pair dual and primal coordinates in the same basis.

python
def pair(left: object, right: object) -> Expression: ...

Ordered product of two atomic coordinate values or maps.

python
def tensor_product(left: object, right: object) -> Expression: ...

Swap the two factors of a tensor product; for a map, both endpoints are permuted.

python
def permute_factors(value: object, permutation: Sequence[int]) -> Expression: ...

Reference to an observable declared in a Component.

python
@final
class Observable(Expression):
def __init__(self, _token: Never, _component: object=..., _name: str='') -> None: ...

Directional variation of an energy functional with respect to selected bindings, holding others fixed.

python
def variation(value: Observable | Expression, *, wrt: Expression, direction: Expression, holding: Sequence[Expression]=()) -> Expression: ...

Contract explicitly paired tensor axes.

python
def contract(left: object, right: object, *, axes: Sequence[tuple[int, int]]) -> Expression: ...

Right-handed cross product of Cartesian 3-vectors, without complex conjugation.

python
def cross(left: object, right: object) -> Expression: ...

Cartesian curl: 3D vector, 2D vector-to-scalar, or 2D scalar-to-vector.

python
def curl(value: object) -> Expression: ...

Tangential trace n × value on the parent boundary; a scalar in 2D.

python
def tangential_trace(value: object, *, on: Support | None=None, from_: Support | None=None) -> Expression: ...

A non-strict mathematical condition with lhs greater than or equal to rhs.

python
@final
class Inequality:
def __init__(self, token: Never, lhs: Expression, rhs: Expression) -> None: ...
@property
def lhs(self) -> Expression: ...
@property
def rhs(self) -> Expression: ...
def __bool__(self) -> bool: ...

Complementarity condition: two nonnegative operands, at least one of which is zero.

python
@final
class Complementarity:
def __init__(self, token: Never, lhs: Expression, rhs: Expression) -> None: ...
@property
def lhs(self) -> Expression: ...
@property
def rhs(self) -> Expression: ...
def __bool__(self) -> bool: ...

Require lhs >= rhs; how it is enforced numerically is chosen separately.

python
def inequality(lhs: object, rhs: object) -> Inequality: ...

Require two operands to be nonnegative with at least one of them zero.

python
def complementarity(left: Expression, right: Expression) -> Complementarity: ...

Equality comparison expression.

python
def equal(left: object, right: object) -> Expression: ...

Inequality comparison expression.

python
def not_equal(left: object, right: object) -> Expression: ...

Less-than comparison expression.

python
def less(left: object, right: object) -> Expression: ...

Less-than-or-equal comparison expression.

python
def less_equal(left: object, right: object) -> Expression: ...

Greater-than comparison expression.

python
def greater(left: object, right: object) -> Expression: ...

Greater-than-or-equal comparison expression.

python
def greater_equal(left: object, right: object) -> Expression: ...

Logical NOT expression.

python
def logical_not(value: object) -> Expression: ...

Logical AND expression.

python
def logical_and(left: object, right: object) -> Expression: ...

Logical OR expression.

python
def logical_or(left: object, right: object) -> Expression: ...

A periodic clock declared in a Component; equal periods do not make two clocks the same.

python
@final
class Clock:
...

Author a public Component and bind an instance of it.

python
@final
class Component:
def set_notation(self, name: str, notation: Notation) -> None: ...
def counts(self, space: FiniteSpace, components: Sequence[Expression | int]) -> Expression: ...
def coordinates(self, space: FiniteSpace, components: Sequence[Expression | int | float | complex], *, dual: bool=False) -> Expression: ...
def identity(self, space: FiniteSpace, *, dual: bool=False) -> Expression: ...
def linear_map(self, source: FiniteSpace, target: FiniteSpace, rows: Sequence[Sequence[object]], *, source_dual: bool=False, target_dual: bool=False) -> Expression: ...
def index(self, set: IndexSet, value: Expression | int) -> Expression: ...
def sum(self, body: Callable[[Expression], object], *, over: IndexSet, name: str='i') -> Expression: ...
def product(self, body: Callable[[Expression], object], *, over: IndexSet, name: str='i') -> Expression: ...
def min(self, body: Callable[[Expression], object], *, over: IndexSet, name: str='i') -> Expression: ...
def max(self, body: Callable[[Expression], object], *, over: IndexSet, name: str='i') -> Expression: ...
def index_set(self, name: str, *, extent: int, doc: str | None=None) -> IndexSet: ...
def event(self, name: str, guard: Expression | int | float, *, direction: Literal['any', 'rising', 'falling'], priority: int=0, doc: str | None=None) -> Event: ...
def clock(self, name: str, *, period_s: Fraction | int, phase_s: Fraction | int=0, doc: str | None=None) -> Clock: ...
def initial(self, *equations: tuple[object, object], left: object=None, right: object=None, doc: str | None=None) -> None: ...
def volume(self, name: str, *, dimensions: int, doc: str | None=None) -> Support: ...
def boundary(self, name: str, *, parent: Support, doc: str | None=None) -> Support: ...
def complete_exterior(self, name: str, *, parent: Support, doc: str | None=None) -> BoundarySet: ...
def boundaries(self, *members: Support) -> BoundarySelectionSet: ...
@overload
def parameter(self, name: str, *, value_type: Record | ImportedRecord, doc: str | None=None) -> RecordParameter: ...
@overload
def parameter(self, name: str, *, value_type: ValueType, doc: str | None=None) -> Expression: ...
def coordinate(self, name: str, *, value_type: ValueType, on: Support, factor: Support, axis: int | None=..., doc: str | None=...) -> Expression: ...
def let_alias(self, name: str, expression: Expression | int | float | complex, *, value_type: ValueType | None=None, on: Support | None=None, at: Clock | Event | None=None, doc: str | None=None) -> Expression: ...
def property(self, name: str, *, contract: PropertyContract, doc: str | None=None) -> PropertyRequirement: ...
@overload
def field(self, name: str, *, on: Support | None=None, value_type: Record | ImportedRecord, role: FieldRole, at: Clock | None=None, spatial_regularity: SpatialRegularity=SpatialRegularity.Unspecified, doc: str | None=None) -> RecordField: ...
@overload
def field(self, name: str, *, on: Support | None=None, value_type: ValueType, role: FieldRole, at: Clock | None=None, spatial_regularity: SpatialRegularity=SpatialRegularity.Unspecified, doc: str | None=None) -> Expression: ...
def observable(self, name: str, expression: Expression | int | float | complex, *, value_type: ValueType, on: Support | None=None, integrate_over: Support | None=None, doc: str | None=None) -> Observable: ...
def relation(self, name: str, condition: Equation | Inequality | Complementarity, *additional_conditions: Equation | Inequality | Complementarity, on: Support | None=None, at: Clock | Event | None=None, doc: str | None=None) -> Relation: ...
def law(self, name: str, *, on: Support, flux: Expression, source: Expression, storage: Expression | None=None, doc: str | None=None) -> Relation: ...
def test(self, name: str, *, for_: Expression, dimension: Dimension | None=None, regularity: str | None=None, zero_on: Support | BoundarySelectionSet | None=None) -> Expression: ...
def weak_form(self, name: str, relations: Sequence[Relation], *, equations: Sequence[tuple[object, object]], doc: str | None=None) -> None: ...
def harmonic_form(self, name: str, relations: Sequence[Relation], *, angular_frequency: object, convention: str, normalization: str, excitations: Sequence[tuple[Expression, object]], amplitudes: Sequence[tuple[str, Expression, ValueType]], doc: str | None=None) -> None: ...
def port(self, name: str, *, connector: Connector, on: Support | None=None, doc: str | None=None) -> Port | FieldPort: ...
def connect(self, *ports: Port, over: BoundaryMember | None=None, doc: str | None=None) -> None: ...
def connect_periodic(self, first: FieldPort, second: FieldPort, *, doc: str | None=None) -> None: ...
def instance(self, name: str, *, component: Component | ComponentRef, bindings: Mapping[str, object], doc: str | None=None) -> Mapping[str, Expression | Port]: ...
def clock_requirement(self, name: str, *, doc: str | None=None) -> Clock: ...
def field_requirement(self, name: str, *, value_type: ValueType, role: FieldRole, on: Support | None=None, at: Clock | None=None, spatial_regularity: SpatialRegularity=SpatialRegularity.Unspecified, doc: str | None=None) -> Expression: ...
def set_default(self, parameter: Expression, value: Expression | int | float | complex) -> None: ...
def input(self, name: str, *, value_type: ValueType, on: Support | None=None, at: Clock | None=None, spatial_regularity: SpatialRegularity=SpatialRegularity.Unspecified, doc: str | None=None) -> Expression: ...
def output(self, name: str, *, value_type: ValueType, on: Support | None=None, at: Clock | None=None, spatial_regularity: SpatialRegularity=SpatialRegularity.Unspecified, doc: str | None=None) -> Expression: ...

Scalar physical connector with across and through quantities, declared in one Module.

python
class Connector:
def __init__(self, token: Never, owner: object, name: str, across: tuple[str, object], through: tuple[str, object], doc: tuple[str, ...]) -> None: ...

Requirement for the complete exterior boundary of a declared parent volume.

python
@final
class BoundarySet(Support):
def __init__(self, token: Never, component: Component, name: str, parent: Support) -> None: ...
def member(self, name: str) -> BoundaryMember: ...

One named part of a complete exterior boundary.

python
@final
class BoundaryMember(Support):
def __init__(self, token: Never, boundary_set: BoundarySet, name: str) -> None: ...

An explicit finite set of boundaries with the same parent volume.

python
@final
class BoundarySelectionSet:
def __init__(self, token: Never, component: Component, parent: Support, members: Sequence[Support]) -> None: ...

Field connector pairing a trace and a flux of declared shape and frame.

python
class FieldConnector(Connector):
def __init__(self, token: Never, owner: object, name: str, trace: tuple[str, object], flux: tuple[str, object], spatial_vector: bool, doc: tuple[str, ...]) -> None: ...

A field port on a boundary, or a finite family of such ports.

python
@final
class FieldPort(Port):
def __init__(self, token: Never, component: Component, name: str, connector: FieldConnector, support: Support, family: tuple[str, BoundarySet | BoundarySelectionSet] | None=None, selector: Support | None=None) -> None: ...
def __getitem__(self, boundary: Support) -> FieldPort: ...

Physical port whose declared quantities are available as attributes.

Use member(name) when a quantity name clashes with a Python attribute.

python
class Port:
def __init__(self, token: Never, owner: object, name: str, connector: Connector) -> None: ...
def __getattr__(self, name: str) -> Expression: ...
def member(self, name: str) -> Expression: ...

Reference to a public Component of an imported module.

python
@final
class ComponentRef:
def __init__(self, token: Never, imported: ModuleRef, name: str, signature: Sequence[object], ports: Sequence[object], supports: Sequence[object]) -> None: ...
@property
def name(self) -> str: ...

An equation with ordered left and right sides; it has no Python truth value.

python
@final
class Equation:
def __init__(self, token: Never, lhs: Expression, rhs: Expression) -> None: ...
@property
def lhs(self) -> Expression: ...
@property
def rhs(self) -> Expression: ...
def __bool__(self) -> bool: ...

Build an equation from two expressions or literals.

python
def equation(lhs: object, rhs: object) -> Equation: ...

A closed Eqiora expression. Python == does not build an equation; use equation.

python
class Expression:
def __add__(self, other: Expression | float | int | complex, /) -> Expression: ...
def __radd__(self, other: float | int, /) -> Expression: ...
def __sub__(self, other: Expression | float | int | complex, /) -> Expression: ...
def __rsub__(self, other: float | int, /) -> Expression: ...
def __mul__(self, other: Expression | float | int | complex, /) -> Expression: ...
def __rmul__(self, other: float | int, /) -> Expression: ...
def __truediv__(self, other: Expression | float | int | complex, /) -> Expression: ...
def __rtruediv__(self, other: float | int, /) -> Expression: ...
def __pow__(self, exponent: int, /) -> Expression: ...
def __bool__(self) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __le__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __neg__(self) -> Expression: ...
def __getitem__(self, index: int | Expression | slice) -> Expression: ...

Enum declared in a Module.

python
@final
class Enum:
@property
def name(self) -> str: ...
@property
def members(self) -> tuple[str, ...]: ...
@property
def value_type(self) -> ValueType: ...
def member(self, name: str) -> Expression: ...

A record type with ordered, typed fields, declared in one Module.

python
class Record:
def __init__(self, token: Never=..., *, source: Module | None=None, name: str='', syntax_name: str | None=None, members: Sequence[tuple[str, ValueType]]=(), syntax: Sequence[object]=(), doc: tuple[str, ...]=()) -> None: ...
@property
def name(self) -> str: ...
@property
def members(self) -> Mapping[str, ValueType]: ...
def __call__(self, /, **members: object) -> Expression: ...

Read-only description of a public Record from an import.

python
@final
class ImportedRecord:
@property
def name(self) -> str: ...
@property
def members(self) -> Mapping[str, str]: ...
def __call__(self, /, **members: object) -> Expression: ...

Handle to a Field of record type; every member shares the Field’s role and clock.

python
@final
class RecordField(Expression):
def __init__(self, component: Component, name: str, record: Record) -> None: ...
def member(self, name: str) -> Expression: ...

Handle to a Parameter of record type; its members are ordinary typed expressions.

python
@final
class RecordParameter(Expression):
def __init__(self, component: Component, name: str, record: Record) -> None: ...
def member(self, name: str) -> Expression: ...

A crossing event declared in a Component.

python
@final
class Event:
...

An immutable typed material composition declared in a Module.

python
@final
class MaterialComposition:
def __getitem__(self, name: str) -> PropertyRelease: ...

Validated notation for a declaration, given as one complete @{...} block.

python
@final
class Notation:
def __new__(cls, island: str) -> Notation: ...
@property
def canonical(self) -> str: ...
def __str__(self) -> str: ...

Operator declared in a Module. Call it with named arguments.

python
class Operator:
def __call__(self, /, **arguments: object) -> Expression: ...

A typed property contract declared in a Module.

python
class PropertyContract:
def input(self, name: str) -> Expression: ...

A property requirement, applied by passing its inputs by name.

python
@final
class PropertyRequirement(Expression):
def __init__(self, _token: Never, component: object, name: str, contract: PropertyContract) -> None: ...
def __call__(self, /, **arguments: object) -> Expression: ...

A constant scalar property release declared in a Module.

python
class PropertyRelease:
...

A relation declared in a Module.

python
@final
class Relation:
...

An Eqiora module built in Python; it becomes immutable once emitted or compiled.

python
@final
class Module:
def dimension(self, name: str, value: Dimension, *, doc: str | None=None) -> Dimension: ...
def set_notation(self, name: str, notation: Notation) -> None: ...
def connector(self, name: str, *, across: tuple[str, ValueType], through: tuple[str, ValueType], doc: str | None=None) -> Connector: ...
def field_connector(self, name: str, *, trace: tuple[str, ValueType], flux: tuple[str, ValueType], spatial_vector: bool=False, doc: str | None=None) -> FieldConnector: ...
def operator(self, name: str, *, inputs: Mapping[str, ValueType], result_type: ValueType, body: Callable[..., object], doc: str | None=None) -> Operator: ...
def record(self, name: str, *, members: Mapping[str, ValueType], doc: str | None=None) -> Record: ...
def enum(self, name: str, *, members: Sequence[str], doc: str | None=None) -> Enum: ...
def space(self, name: str, *, labels: Sequence[str] | None=None, factors: Sequence[FiniteSpace] | None=None, doc: str | None=None) -> FiniteSpace: ...
def __init__(self, name: str, *declarations: _ModelDeclaration, package: str='eqiora.local_project') -> None: ...
@classmethod
def parse(cls, name: str, source: str, *, package: str='eqiora.local_project') -> Module: ...
def import_module(self, alias: str, module: Module | None=None, *, path: str | PathLike[str] | None=None) -> ModuleRef: ...
def component(self, name: str, *, doc: str | None=None) -> Component: ...
def model(self, name: str, *, doc: str | None=None) -> Component: ...
def property_contract(self, name: str, *, value_type: ValueType, inputs: Mapping[str, ValueType] | None=None, derivatives: Literal['value_only', 'first_partials', 'first_open_intervals']='value_only', branch: str | None=None, doc: str | None=None) -> PropertyContract: ...
def property_table_release(self, name: str, *, implements: PropertyContract, data: str, axis_unit: Unit, source_unit: Unit, validity: tuple[object, object], citation: str, license: str, branch: str='single', doc: str | None=None) -> PropertyRelease: ...
def property_release(self, name: str, *, implements: PropertyContract, value: Expression | int | float | complex | Sequence[object], source_unit: Unit, source_scale: int | float, citation: str, license: str, validity: Expression | bool | None=None, branch: str | None=None, outside: Literal['reject']='reject', doc: str | None=None) -> PropertyRelease: ...
def material_composition(self, name: str, *, properties: Mapping[str, PropertyRelease], doc: str | None=None) -> MaterialComposition: ...
def to_eqi(self) -> str: ...
def write_eqi(self, path: str | PathLike[str]) -> None: ...

Raised when a Module draft is structurally invalid.

python
@final
class ModuleError(ValueError):
...

An explicit module import; its Components are available as references.

python
@final
class ModuleRef:
def __init__(self, token: Never, owner: object, alias: str, target: Module) -> None: ...
def property_contract(self, name: str) -> PropertyContract: ...
def property_release(self, name: str) -> PropertyRelease: ...
def dimension(self, name: str) -> Dimension: ...
def record(self, name: str) -> ImportedRecord: ...
def enum(self, name: str) -> Enum: ...
def space(self, name: str) -> FiniteSpace: ...
def component(self, name: str) -> ComponentRef: ...
def operator(self, name: str) -> Operator: ...
def connector(self, name: str) -> Connector | FieldConnector: ...

A volume or boundary support declared in a Module.

python
class Support:
...

Construct an array with ordered channel components.

python
def array(values: Sequence[object]) -> Expression: ...

Ordered enum cases; the compiler checks that every member is covered and branch types agree.

python
def case(value: object, arms: Sequence[tuple[Expression, object]]) -> Expression: ...

Spatial coordinate along axis.

python
def coordinate(axis: int) -> Expression: ...

Return the bilinear dot product without complex conjugation.

python
def dot(left: Expression | float | int | complex, right: Expression | float | int | complex) -> Expression: ...

Return the inner product, conjugating the first argument.

python
def inner(left: Expression | float | int | complex, right: Expression | float | int | complex) -> Expression: ...

Divergence of an expression.

python
def div(value: Expression) -> Expression: ...

Gradient of an expression.

python
def grad(value: Expression) -> Expression: ...

Integral over a volume or boundary Support declared in the Module.

python
def integrate(domain: Support, integrand: Expression | float | int | complex) -> Expression: ...

Conditional expression; both branches are type-checked and one is evaluated.

python
def if_else(condition: object, then_value: object, else_value: object) -> Expression: ...

Isotropic tensor lift of a scalar expression (the scalar times the identity).

python
def isotropic_lift(value: Expression) -> Expression: ...

Mathematical constants for use in expressions.

python
math: _Math

Contraction of an expression with the outward boundary normal.

python
def normal(value: object, *, on: Support | None=None, from_: Support | None=None) -> Expression: ...

Integer ordinal of an index.

python
def ordinal(value: Expression) -> Expression: ...

Differentiate a real scalar polynomial with respect to one independent binding.

holding lists other independent bindings that are held fixed; the compiler checks that they are distinct and that dimensions agree.

python
def partial(value: object, *, wrt: Expression, holding: Sequence[Expression]=()) -> Expression: ...

Build a point-evaluation expression with a dimensioned value for every support coordinate.

python
def evaluate(value: object, *, at: Sequence[tuple[Expression, object]], side: Literal['lower', 'upper'] | None=None) -> Expression: ...

Pull back a scalar through an explicit map between coordinate supports.

python
def pullback(value: object, *, from_: Sequence[Expression], at: Sequence[tuple[Expression, object]]) -> Expression: ...

Signed local Jacobian determinant of a coordinate map; it may be zero where the map is singular.

python
def jacobian_determinant(*, from_: Sequence[Expression], at: Sequence[tuple[Expression, object]]) -> Expression: ...

Absolute Jacobian determinant of an invertible volume map.

python
def volume_jacobian(*, from_: Sequence[Expression], at: Sequence[tuple[Expression, object]]) -> Expression: ...

Dimensionless local orientation (±1) of an invertible map.

python
def map_orientation(*, from_: Sequence[Expression], at: Sequence[tuple[Expression, object]]) -> Expression: ...

Jacobian-vector product of a scalar along ordered input directions, each in its input’s units.

python
def jvp(value: object, *, wrt: Sequence[Expression], tangent: Sequence[object]) -> Expression: ...

Vector-Jacobian product: pull a scalar output cotangent back to one input.

python
def vjp(value: object, *, wrt: Expression, cotangent: object) -> Expression: ...

Time derivative of a continuous State; the compiler checks the role and activation.

python
def derivative(value: Expression) -> Expression: ...

Continuous time in seconds.

python
def time() -> Expression: ...

Value of a State before the current tick; the compiler checks the clock and context.

python
def pre(value: Expression) -> Expression: ...

Value of a State after the current tick; the compiler checks the clock and context.

python
def next(value: Expression) -> Expression: ...

Input quantity with a unit; the compiler converts it to coherent SI.

python
def quantity(value: int | float | Decimal, unit: Unit) -> Expression: ...

Integer quotient truncated toward zero; overflow and division by zero are errors.

python
def quotient(left: Expression | int, right: Expression | int) -> Expression: ...

Integer remainder; a nonzero result has the sign of the dividend.

python
def remainder(left: Expression | int, right: Expression | int) -> Expression: ...

Convert an integer to a real; binary64 rounding can lose precision for large values.

python
def to_real(value: Expression | int) -> Expression: ...

Convert a finite, integral, dimensionless real to a signed 64-bit integer.

python
def to_integer(value: Expression | float | int) -> Expression: ...

Frobenius contraction of two tensor expressions.

python
def frobenius(left: Expression, right: Expression) -> Expression: ...

Symmetric part of a tensor expression.

python
def symmetric_part(value: Expression) -> Expression: ...

Construct a spatially uniform tensor value in an explicit Cartesian frame.

The compiler checks the frame, shape, units, and scalar domain. Use array for channel axes.

python
def tensor_value(*, frame: Support, components: Sequence[object] | Expression) -> Expression: ...

Trace of an expression on a boundary.

python
def trace(value: object, *, on: Support | None=None, from_: Support | None=None) -> Expression: ...