How do you save an Environment?

Help
Cerin
2012-04-25
2013-04-25
  • Cerin
    Cerin
    2012-04-25

    How do you completely save the state of an environment?

    I tried using Save() and SaveFacts(), but these don't seem to store the executed state of the RETE network, so initializing a blank environment and then using Load() and LoadFacts() results in an Environment that thinks it has to re-run all the matched rules.

     
  • Actually they don't: there's actually no way in CLIPS to save the complete state of an environment. Save() only saves the structure of an environment, that is its constructs, and SaveFacts() only saves the asserted facts. Since an executing environment is handled by CLIPS internally (in its RETE implementation), it's impossible to retrieve it from Python…

    Excuse my curiosity, but what do you use it for? Maybe there is another way to handle the problem - like having an always-running PyCLIPS server that keeps its state separated from the clients.

    F.

     
  • Cerin
    Cerin
    2012-04-29

    Thanks for the feedback. Yeah, I figured as much after reading through the Clips manual. I'm trying to implement a lightweight reasoning system into a web application, which serializes the environment to the database when not in use. Running a Clips server is one option, but adds more complexity than I'd like.

    After digging through the Clips code, adding this functionality with the help of tpl (http://tpl.sourceforge.net/) probably wouldn't be too hard, but I'm not sure I want to maintain a forked version of Clips, and I'm not sure it's strictly necessary for my application. The RHS of my rules only contain Python callbacks to my app, so I can effectively unserialize a Clips environment by using Load(), LoadFacts(), and then Run() to repopulate the RETE network. Not as fast as simply loading the network from a file, but for now it should work until it becomes a serious bottleneck.