# Custom recorder on stages with different constraints

**URL:** <https://discourse.julialang.org/t/custom-recorder-on-stages-with-different-constraints/112718>\
**Category:** Optimization (Mathematical)\
**Tags:** sddp\
**Created:** [April 9, 2024, 10:52am UTC](https://discourse.julialang.org/t/custom-recorder-on-stages-with-different-constraints/112718 "2024-04-09T10:52:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FelixSchmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/felixschmidt/32/202177_2.png) [@FelixSchmidt](https://discourse.julialang.org/u/FelixSchmidt)\
**Post date:** [April 9, 2024, 10:52am UTC](https://discourse.julialang.org/t/custom-recorder-on-stages-with-different-constraints/112718/1 "2024-04-09T10:52:59Z")

</div>

Hi Oscar,  
I’ve been having issues with creating a custom recorder in SDDP.simulate. I have a capacity expansion problem where stage 1 covers the investment decision and stages 2,…T are monthly dispatch problems at hourly resolution connected by storage level state variables (and the capacity decisions from stage 1). In each dispatch stage I have an _internal_ storage plant equation (as opposed to an external one connecting stages) of which I would like to get the dual values in a given simulation.

My problem is the following: Since these constraints do not appear in the investment stage 1, the custom recorder is throwing me an error. Is there a way to skip a node in recording dual control variables?

Thank you very much!

Felix

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 9, 2024, 7:41pm UTC](https://discourse.julialang.org/t/custom-recorder-on-stages-with-different-constraints/112718/2 "2024-04-09T19:41:10Z")

</div>

The custom recorder is an arbitrary Julia function. So you could do something like:

```julia
function my_custom_recorder(sp::JuMP.Model)
    dict = JuMP.object_dictionary(sp)
    if !haskey(dict, :demand_constraint)
        return NaN
    end
    return JuMP.dual(dict[:demand_constraint])
end

# and then

    custom_recorders = Dict{Symbol,Function}(
        :price => my_custom_recorder,
    )

```

---

<div class="post-metadata">

**Author:** ![FelixSchmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/felixschmidt/32/202177_2.png) [@FelixSchmidt](https://discourse.julialang.org/u/FelixSchmidt)\
**Post date:** [April 9, 2024, 9:19pm UTC](https://discourse.julialang.org/t/custom-recorder-on-stages-with-different-constraints/112718/3 "2024-04-09T21:19:59Z")

</div>

Hi Oscar,  
just what I was looking for! Thank you!

Best

Felix
