-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deferring evaluation of mutable objects #67
Comments
There's also |
@schmrlng, re: #68 (comment), the keyword constructor wouldn't work with |
But having an additional outer constructor with a required keyword argument instead of replacing the current outer constructor might be a good idea. To support both 0.6 and 0.7: Parameter(model; fixedval=throw(MethodError("keyword argument fixedval not assigned"))) = Parameter(identity, fixedval, model) I think I like that better than Opinions (also regarding kwarg name)? |
I would be happy with that. |
I don't particularly like |
API-wise, one thing I mildly dislike about the function create_model(args...)
X = Matrix{T}(undef, n, m)
vals = Vector{T}(undef, m)
function updater(leaf)
# Do something to calculate both `X` and `vals` from `leaf`
end
model = ...
vars = ...
Xp = Parameter(X, model) # syntax as in #79
valsp = Parameter(vals, model)
# define objective, constraints, etc
return updater, model, vars...
end
Here |
It seems that this issue is the first annoyance for anybody using the package, unfortunately. I'll think about ways to better support your use case. In an earlier implementation of this package everything worked in this 'push' fashion: the user would just be responsible for updating all the problem data before calling Off topic, and it might not be helpful in your case because you want to call the update function with the using Parametron, Random
model = Parametron.MockModel()
n, m = 2, 2
T = Float64
X = Matrix{T}(undef, n, m)
vals = Vector{T}(undef, m)
dummy = Parameter{Nothing}(model) do
println("updating X and vals")
rand!(X)
rand!(vals)
nothing
end
p1 = Parameter(x -> (dummy(); x), X, model)
p2 = Parameter(x -> (dummy(); x), vals, model) so that you get: julia> p1()
updating X and vals
2×2 Array{Float64,2}:
0.0495582 0.981912
0.24826 0.326884
julia> p2()
2-element Array{Float64,1}:
0.47120493476206926
0.7678895316375276 Then the solver still does the work of invalidating parameter values at the beginning of a |
Fix #67, sugar for creating Parameters that are updated externally.
(just continuing our conversation from the QPControl bug)
What about a function
defer(x)
which would do:which would be useful for wrapping mutable objects that should be evaluated "later" rather than eagerly. I realize it's only a one-liner, but it would also remove the need for a
let
block, so:becomes:
defer(x, model)
The text was updated successfully, but these errors were encountered: