How to save (pickle) a model instance in pyomo

后端 未结 2 1333
后悔当初
后悔当初 2020-12-11 12:08

I want to create a model instance and then save it so I can load and solve at a later time (the initialization takes quite long compared to the solving). When I tried this i

2条回答
  •  遥遥无期
    2020-12-11 12:47

    The solution is the cloudpickle module, regular pickle has problems pickling functions. An example:

    import cloudpickle
    
    with open('test.pkl', mode='wb') as file:
       cloudpickle.dump(instance, file)
    
    
    with open('test.pkl', mode='rb') as file:
       instance = cloudpickle.load(file)
    

提交回复
热议问题