Skip to content

Dependency Incompatibility with linopy v0.5+ #73

@CLiu0412

Description

@CLiu0412

ValueError in optimization with linopy >= 0.5.0 (Strict dimension naming)

Description:
Running the workflow with the latest linopy (tested with v0.5.8) causes a ValueError during the optimization phase. This appears to be due to linopy v0.5 enforcing strict dimension naming (force_dim_names=True), which conflicts with how PyPSA (v0.34.1) or ISPyPSA constructs constraints (specifically nodal balance constraints causing unnamed dimensions like dim_0).

Traceback:
File ".../pypsa/optimization/constraints.py", line 666, in define_nodal_balance_constraints
n.model.add_constraints(lhs, "=", rhs, name=f"Bus{suffix}-nodal_balance", mask=mask)
File ".../linopy/model.py", line 672, in add_constraints
self.check_force_dim_names(data)
ValueError: Added data contains non-customized dimension names. This is not allowed when setting force_dim_names to True.

Steps to Reproduce:
Install ISPyPSA with linopy>=0.5.0.
Run any standard workflow (e.g., test_workflow_2025.py).
Updates fail at network.optimize.solve_model().

Suggested Fix: Either: Pin Dependencies: Update pyproject.toml to restrict linopy<0.5.0 (and xarray<2024.06 if using older linopy).
Update Code: Refactor the constraint generation in ISPyPSA to ensure all xarray objects passed to linopy have named dimensions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions