Skip to content

sum_next_n and roll don't accept parameters as the offset #827

@jmorrisnrel

Description

@jmorrisnrel

What happened?

Trying to use a user-defined parameter as the offset for both sum_next_n and roll fail with different error messages.

Below is an example of constraints for user-defined minimum up and downtime limits on technologies. The user defined parameter in this instance needs to control the number of timesteps the constraints sum on a per-tech/node basis.

parameters:
  minimum_uptime:
    default: 0
    resample_method: mean
    title: Minimum uptime.
    description: >-
      Minimum number of consecutive timesteps a unit must remain online after starting up.
      Only valid for technologies with integer dispatch and cap_method set to 'integer'.
    unit: timesteps.

  minimum_downtime:
    default: 0
    resample_method: mean
    title: Minimum downtime.
    description: >-
      Minimum number of consecutive timesteps a unit must remain offline after shutting down.
      Only valid for technologies with integer dispatch and cap_method set to 'integer'.
    unit: timesteps.

constraints:
  minumum_uptime_integer_dispatch:
    description: >
      Enforce minimum uptime for integer dispatch technologies.
    foreach: [nodes, techs, timesteps]
    where: "integer_dispatch AND minimum_uptime"
    equations:
      - expression: > 
           operating_units >= sum_next_n(unit_start, timesteps, 4)

  minumum_downtime_integer_dispatch:
    description: >
      Enforce minimum downtime for integer dispatch technologies.
    foreach: [nodes, techs, timesteps]
    where: "integer_dispatch AND minimum_downtime"
    equations:
      - expression: > 
           operating_units + sum_next_n(unit_stop, timesteps, minimum_downtime) <= purchased_units

Trying to actually pass an integer parameter value into sum_next_n results in a
TypeError: only length-1 arrays can be converted to Python scalars

It looks like the entire parameter DataArray gets passed in as N in the SumNexN.as_array() function, so it is parsing the parameter name in the kwarg, but it doesn't index it to get the value for the specific [node, tech] in the constraint foreach loop.

roll doesn't seem to be parsing the kwarg at all and just fails when it tries to convert the parameter name to an int.
ValueError: invalid literal for int() with base 10: 'test_offset'

I haven't tested the other helper functions but assume get_val_at_index would also have the issue.

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

Version

v0.7.0.dev7

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions