Closed WuSiren closed 2 weeks ago
I've tried to save a trained model as a StochOptFormat but I failed:
ERROR: StochOptFormat does not support writing after a call to `SDDP.train`.
But I need to save the trained model so that other people can reproduce the results I obtained easily. Could you please provide some advice? Thanks!
You can try https://sddp.dev/stable/apireference/#SDDP.write_to_file, but it is still experimental.
What I have done was to use https://sddp.dev/stable/apireference/#SDDP.write_cuts_to_file and https://sddp.dev/stable/apireference/#SDDP.read_cuts_from_file.
I create a function to save all the parameters (save_parameters) that I use to create the subproblems into a .json file and then another load function to create the subproblems (load_parameters) using that .json file. Then, I create two functions: save_model, which calls save_parameters and write_cuts_to_file, and load_model, which calls load_parameters and read_cuts_from_file.
You can not save a model to JLD2 because it will contain references to the underlying solver like Gurobi.
As @Thuener suggests, you should write cuts to a file.
Note that StochOptFormat is currently experimental.
My suggestion would be to share the script that rebuilds the model as Julia code, and also share the cuts .json
file that you can read with read_cuts_from_file
.
Thank you very much, @Thuener and @odow !
I think it may be necessary for me to get clear one thing that what essentially a trained decision rule is? Is it simply a parameterized function, or a new small optimization problem whose solution is the decision?
Please forgive me for not knowing it deeply enough! 🙏
or a new small optimization problem whose solution is the decision
It's this
or a new small optimization problem whose solution is the decision
It's this
I see. Thanks. If I save the policy using (I got it)SDDP.write_cuts_to_file(model, "myPolicy.json")
, then how should someone else use it after he runs SDDP.read_cuts_from_file(model, "myPolicy.json")
, for example, if he wants to perform in-sample or out-of-sample simulate, or just evaluate the decision rule for some given scenario?
You can try https://sddp.dev/stable/apireference/#SDDP.write_to_file, but it is still experimental.
What I have done was to use https://sddp.dev/stable/apireference/#SDDP.write_cuts_to_file and https://sddp.dev/stable/apireference/#SDDP.read_cuts_from_file.
I create a function to save all the parameters (save_parameters) that I use to create the subproblems into a .json file and then another load function to create the subproblems (load_parameters) using that .json file. Then, I create two functions: save_model, which calls save_parameters and write_cuts_to_file, and load_model, which calls load_parameters and read_cuts_from_file.
Hi, @Thuener ! Is your method same with @odow 's suggestion?
My suggestion would be to share the script that rebuilds the model as Julia code, and also share the cuts
.json
file that you can read withread_cuts_from_file
.
Could you please provide more details on how you save the parameters to a .json
file? According to my understanding, your method can have reproducibility without providing the explicit model script to the user, is it?
without providing the explicit model script to the user
No, you should still provide the script.
See, e.g., https://github.com/odow/SDDP.jl/blob/master/papers/policy_graph/paper.jl and https://github.com/odow/SDDP.jl/blob/master/papers/policy_graph/powder_data.json
Oh, I roughly understand how it works. Thank you very much Prof. @odow ! 🤝
How to save a trained model? I've tried to save it with
JLD2
, but when I loaded the model, it told:So is there any proper method to saving a SDDP model?