Skip to content

Data Types

data_types

Core data types for optimization results.

This module defines the fundamental data types used to represent different aspects of optimization problems: design variables, objectives, constraints, observables, and extensible custom data types.

Classes

DataTypeCategory

Bases: str, Enum

Categories of data in optimization results.

OptimizationDirection

Bases: str, Enum

Direction of optimization for objectives.

ConstraintType

Bases: str, Enum

Types of constraints.

VariableMetadata

Bases: BaseModel

Base metadata for any variable/parameter in optimization.

Functions
validate_name classmethod
validate_name(v: str) -> str

Ensure name is valid identifier.

Source code in optiscope/core/data_types.py
@field_validator("name")
@classmethod
def validate_name(cls, v: str) -> str:
    """Ensure name is valid identifier."""
    if not v or not v.strip():
        raise ValueError("Name cannot be empty")
    return v.strip()

DesignVariable

Bases: VariableMetadata

Metadata for a design variable (decision variable).

Objective

Bases: VariableMetadata

Metadata for an objective function.

Functions
normalize_value
normalize_value(value: float) -> float

Normalize objective value to [0, 1] range if ideal and nadir are known.

Parameters:

Name Type Description Default
value float

Raw objective value

required

Returns:

Type Description
float

Normalized value (0=ideal, 1=nadir)

Source code in optiscope/core/data_types.py
def normalize_value(self, value: float) -> float:
    """
    Normalize objective value to [0, 1] range if ideal and nadir are known.

    Args:
        value: Raw objective value

    Returns:
        Normalized value (0=ideal, 1=nadir)
    """
    if self.ideal_value is None or self.nadir_value is None:
        return value

    if abs(self.nadir_value - self.ideal_value) < 1e-10:
        return 0.0

    return (value - self.ideal_value) / (self.nadir_value - self.ideal_value)

Constraint

Bases: VariableMetadata

Metadata for a constraint.

Functions
is_violated
is_violated(value: float) -> bool

Check if constraint is violated.

Parameters:

Name Type Description Default
value float

Constraint function value

required

Returns:

Type Description
bool

True if constraint is violated

Source code in optiscope/core/data_types.py
def is_violated(self, value: float) -> bool:
    """
    Check if constraint is violated.

    Args:
        value: Constraint function value

    Returns:
        True if constraint is violated
    """
    if self.constraint_type == ConstraintType.EQUALITY:
        return abs(value - self.reference_value) > self.tolerance
    elif self.constraint_type == ConstraintType.INEQUALITY:
        # g(x) <= reference_value
        return value > self.reference_value + self.tolerance
    elif self.constraint_type == ConstraintType.BOUND:
        if self.lower_bound is not None and value < self.lower_bound - self.tolerance:
            return True
        if self.upper_bound is not None and value > self.upper_bound + self.tolerance:
            return True
    return False

Observable

Bases: VariableMetadata

Metadata for an observable (computed quantity that's not an objective or constraint).

Observables are additional quantities computed during optimization that may be useful for analysis but don't directly affect the optimization.

CustomDataType

Bases: VariableMetadata

Metadata for custom/user-defined data types.

This allows users to add arbitrary data types beyond the standard categories.