Skip to content

ecology

cybersyn.ecology

Dataclasses to save the ecology and the planned ecology.

TODO:

Add PlannedEcology class or merge it with planned economy.

Ecology

Bases: BaseModel

Dataclass with validations that stores the whole economy's information.

num_pollutants: int property

Number of products in the economy.

PlannedEcology(pollutants=list()) dataclass

Dataclass that stores the whole planned economy.

Parameters:

Name Type Description Default
activity list[NDArray]

list with the planned activity for all sectors in each period.

required
production list[NDArray]

list with the planned production for all product in each period.

required
surplus list[NDArray]

The surplus production at the end of each period.

required
total_import list[NDArray]

list of total imports in each period.

required
export_deficit list[float]

list export deficit at the end of each period.

required
worked_hours list[float]

list of total worked hours in each period.

required

TargetEcology

Bases: BaseModel

Dataclass with validations that stores the whole economy's information.

num_pollutants: int property

Number of products in the economy.

periods: int property

Number of products in the economy.

equal_sizes(matrices, info)

Assert that all the inputed matrices have the same size.

Source code in cybersyn/ecology.py
60
61
62
63
64
65
66
67
@field_validator("pollutants")
def equal_sizes(cls, matrices: MatrixList, info: FieldValidationInfo) -> MatrixList:
    """Assert that all the inputed matrices have the same size."""
    sizes = [matrix.size for matrix in matrices]
    if not all([size == sizes[0] for size in sizes]):
        raise ShapesNotEqualError
    logging.info(f"{info.field_name} has size {sizes[0]}")
    return matrices