Skip to content

Implement time shift support in expression evaluation#190

Closed
aoustry wants to merge 2 commits intomainfrom
claude/implement-time-functions-A2aJz
Closed

Implement time shift support in expression evaluation#190
aoustry wants to merge 2 commits intomainfrom
claude/implement-time-functions-A2aJz

Conversation

@aoustry
Copy link
Copy Markdown
Collaborator

@aoustry aoustry commented Mar 26, 2026

Summary

This PR adds support for time shifting in expression evaluation by introducing a shift() method to the ValueProvider interface and implementing time shift evaluation in the expression visitor.

Key Changes

  • Abstract method addition: Added abstract shift(offset: int) method to ValueProvider interface to enable temporal offset operations
  • Time shift evaluation: Implemented time_shift() method in EvaluationVisitor to evaluate time-shifted expressions by computing the shift offset and creating a new evaluation context with the shifted timestep
  • Implementation across providers: Added shift() implementations to all ValueProvider implementations:
    • EvaluationContext: Returns self (no-op for base context)
    • _make_value_provider in optimization.py: Creates new provider with adjusted timestep
    • Fallback implementation in optimization.py: Returns self (no-op)
    • ExtraOutputValueProvider: Returns self (no-op)
  • Test coverage: Updated test mock to implement the new shift() method

Implementation Details

The time shift evaluation works by:

  1. Evaluating the time shift expression to get an integer offset
  2. Creating a new EvaluationVisitor with a shifted context (via context.shift(offset))
  3. Evaluating the operand within this shifted context

This allows expressions to reference values at different timesteps during evaluation.

https://claude.ai/code/session_011kQZpMxUpTSdBHFe3F7unJ

claude added 2 commits March 26, 2026 11:30
Variable bounds containing TimeShiftNode were raising NotImplementedError
when evaluated. Added shift() to ValueProvider so the evaluator can
evaluate shifted sub-expressions at the correct timestep (t + offset).

https://claude.ai/code/session_011kQZpMxUpTSdBHFe3F7unJ
Adds eval_at(timestep) and all_block_timesteps() to ValueProvider so
the evaluator can handle absolute timestep evaluation (time_eval) and
aggregation over all timesteps (all_time_sum). time_sum reuses the
existing shift() to sum the operand over a relative shift range.

https://claude.ai/code/session_011kQZpMxUpTSdBHFe3F7unJ
@aoustry aoustry closed this Mar 26, 2026
@aoustry aoustry deleted the claude/implement-time-functions-A2aJz branch March 27, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants