kdavies4 / ModelicaRes

Set up, analyze, and plot Modelica simulations in Python
http://kdavies4.github.io/ModelicaRes/
Other
51 stars 20 forks source link

simulators not implemented? #29

Open saroele opened 9 years ago

saroele commented 9 years ago

Hi Kevin,

we're trying to set up MPC (model predictive control) with Modelica, and we need a continue-run framework. We can implement it with dymosim.exe or pyfmi, and we're happy to see that you have implemented this functionality. However, when we install mdoelica res with pip, the following doesn't work::

from modelicares.exps.simulators import dymosim

Any idea why not? And is it possible to do continue-simulations with pyfmi too? Thanks, Roel

arnoutaertgeerts commented 9 years ago

@saroele Kevin and I implemented this functionality in the run_models branch which looks like it has been deleted? @kdavies4 do you know how this happened?

kdavies4 commented 9 years ago

I merged it into the main branch, although it still needs some more work before release (documentation and general cleanup). On Mon, Feb 23, 2015 at 10:16 PM, arnoutaertgeerts notifications@github.com wrote:@saroele Kevin and I implemented this functionality in the run_models branch which looks like it has been deleted? @kdavies4 do you know how this happened?

—Reply to this email directly or view it on GitHub.

arnoutaertgeerts commented 9 years ago

@kdavies4 Have you tried running simulations using the dymosim simulator recently? I saw you made some adjustments but I can't seem to get it working, does it still work for you?

Would it be possible to update the documentation including these new adjustments?

I get this error when trying to run a simulation:

model = "Results/dymosim"
with dymosim(results_dir='Results', StopTime=2500, debug=True) as simulator:
    simulation = simulator.run(model)
---------------------------------------------------------------------------
WindowsError                              Traceback (most recent call last)
<ipython-input-11-0d8c4dc4782e> in <module>()
      1 model = "Results/dymosim"
      2 with dymosim(results_dir='Results', StopTime=2500, debug=True) as simulator:
----> 3     simulation = simulator.run(model)

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\modelicares\exps\simulators.pyc in run(self, model, params, **options)
    766             # Create the file.
    767             run_in_dir([EXEC_PREFIX + self.current_executable, '-i',
--> 768                         dsin_name], model_dir)
    769         orig_dsin_path = os.path.join(model_dir, dsin_name)
    770 

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\modelicares\util.pyc in run_in_dir(args, working_dir, debug)
   1007     # Run the command and print the output if debug is True.
   1008     process = subprocess.Popen(args, cwd=working_dir if working_dir else None,
-> 1009                                stdout=subprocess.PIPE)
   1010     if debug:
   1011         for line in iter(lambda: process.stdout.read(1), ''):

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    708                                 p2cread, p2cwrite,
    709                                 c2pread, c2pwrite,
--> 710                                 errread, errwrite)
    711         except Exception:
    712             # Preserve original exception in case os.close raises.

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
    956                                          env,
    957                                          cwd,
--> 958                                          startupinfo)
    959             except pywintypes.error, e:
    960                 # Translate pywintypes.error to WindowsError, which is

WindowsError: [Error 2] The system cannot find the file specified

I also experienced some errors saying the simulation was still running after it failed. Maybe it is best to delete the temporary folder after a failed simulation?

kdavies4 commented 9 years ago

dymsim works for me, but that's on linux. I'll update the documentation. I haven't had time yet. On Fri, Feb 27, 2015 at 5:47 AM, arnoutaertgeerts notifications@github.com wrote:@kdavies4 Have you tried running simulations using the dymosim simulator recently? I saw you made some adjustments but I can't seem to get it working, does it still work for you?

Would it be possible to update the documentation including these new adjustments?

I get this error when trying to run a simulation:

model = "Results/dymosim" with dymosim(results_dir='Results', StopTime=2500, debug=True) as simulator: simulation = simulator.run(model)


WindowsError Traceback (most recent call last)

in () 1 model = "Results/dymosim" 2 with dymosim(results_dir='Results', StopTime=2500, debug=True) as simulator: ----> 3 simulation = simulator.run(model) c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\modelicares\exps\simulators.pyc in run(self, model, params, **options) 766 # Create the file. 767 run_in_dir([EXEC_PREFIX + self.current_executable, '-i', --> 768 dsin_name], model_dir) 769 orig_dsin_path = os.path.join(model_dir, dsin_name) 770 c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\modelicares\util.pyc in run_in_dir(args, working_dir, debug) 1007 # Run the command and print the output if debug is True. 1008 process = subprocess.Popen(args, cwd=working_dir if working_dir else None, -> 1009 stdout=subprocess.PIPE) 1010 if debug: 1011 for line in iter(lambda: process.stdout.read(1), ''): c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\subprocess.pyc in **init**(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags) 708 p2cread, p2cwrite, 709 c2pread, c2pwrite, --> 710 errread, errwrite) 711 except Exception: 712 # Preserve original exception in case os.close raises. c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite) 956 env, 957 cwd, --> 958 startupinfo) 959 except pywintypes.error, e: 960 # Translate pywintypes.error to WindowsError, which is WindowsError: [Error 2] The system cannot find the file specified I also experienced some errors saying the simulation was still running after it failed. Maybe it is best to delete the temporary folder after a failed simulation? —Reply to this email directly or view it on GitHub.
arnoutaertgeerts commented 9 years ago

@kdavies4 If you need some help, let me know! I just need need a quick write-up of how the code works now to get started :)

kdavies4 commented 9 years ago

That would be awesome. I want to get this cleaned up and released by the next meeting (March 12, I think). On Tue, Mar 03, 2015 at 12:08 AM, arnoutaertgeerts notifications@github.com wrote:@kdavies4 If you need some help, let me know! I just need need a quick write-up of how the code works now to get started :)

—Reply to this email directly or view it on GitHub.

arnoutaertgeerts commented 9 years ago

Probably related to http://stackoverflow.com/questions/21412610/subprocess-popen-using-relative-paths

arnoutaertgeerts commented 9 years ago

Fixed with https://github.com/kdavies4/ModelicaRes/pull/32