Skip to content

sipnet: Drop same-pft segments #4122

Open

Description

@infotroph

write_segmented_configs chooses where to place segment boundaries by parsing either a cycles.csv or an events json file to find the planting events where crop_code changes from its previous state, ie it finds the times when the event file thinks the crop type changed.

At config time, write_segmented-configs uses a user-supplied crop-to-pft mapping function to determine which PFT to use when configuring each segment. But! If several segments in a row have different crop codes that map to the same PFT, we still generate a restart even though results will be identical to what we would have gotten by running all of these as one segment.

Segments are expensive in runtime, scratch space, file count, and conceptual overhead, so we should not be generating extra segments that have no effect.

Proposed fix: In write_segmented_configs, perform PFT mapping as now but then pause and check for segment transitions that keep the same PFT. Drop these and edit the start time of each retained segment to keep the runs continuous.

Deeper design question: It's reasonable to think we'll eventually want to support segmented runs that restart for reasons other than PFT changes. Can we do anything in this patch to make that easier to implement when we need it?

Activity

  1. S1DDHEY commented on Sep 24, 2026

    @S1DDHEY
    Contributor

    Adding to the proposed fix, we could isolate the merge logic behind something like a can_merge_segments() check so future non-PFT restart reasons can be handled, without changing much.

  2. tyagivibhor111-hub commented on Sep 25, 2026

    @tyagivibhor111-hub

    I think the fix should be to keep the existing crop-code based segmentation, map each segment to its PFT as it does now, and then check consecutive segments for the same PFT.

    If two adjacent segments map to the same PFT, we can merge them and adjust the start/end time so the run stays continuous. If the PFT is different, the segment boundary should remain.

    For example:

    crop A → PFT 1
    crop B → PFT 1
    crop C → PFT 2

    would become:

    PFT 1 → PFT 2

    instead of creating a separate restart for crop A → crop B.

    I think keeping this merge step separate, possibly through a can_merge_segments() check, would also fit the proposed fix.

    @infotroph, does this match the expected approach for this issue, or is there a specific behavior you want the implementation to follow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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