Example of test

139 views
Skip to first unread message

Ken Joo Yeap

unread,
Aug 27, 2018, 3:26:48 PM8/27/18
to MPCPy
Hi All, 

I have successfully installed the MPCPy and run the tutorial example, introductory.py however I get many warnings and couldn't really understand the results. Could someone who has already ran the introductory.py once send me the results as a reference for me to compare to? 

Thanks! 

Regards, 
Ken

Ken Joo Yeap

unread,
Aug 27, 2018, 3:47:06 PM8/27/18
to MPCPy
Attached is the output of my test run with Introduction.py. 

If i understand correctly, the simulation only react from line 228 in the introductory.py onwards (see below):

**********************************************************************
File "introductory.py", line 228, in __main__
Failed example:
    emulation = systems.EmulationFromFMU(measurements,
                                         moinfo = moinfo,
                                         weather_data = weather.data,
                                         control_data = control.data,
                                         tz_name = weather.tz_name)

There are other print function before line 228, why did they return anything?

Pardon me for my inexperience art and topic of questioning. Thank you for helping nevertheless! 

Regards, 
Ken
MPCPy_tutorial_results.BASH.py

David Blum

unread,
Aug 27, 2018, 9:01:38 PM8/27/18
to MPCPy
Hey Ken, thanks for posting.

I must say I'm a little confused by the bash output.  It looks like many aspects of MPCPy ran successfully, yet you have many errors which seem to be associated with threading.  Are you running the introductory.py with parallel processing?  I have not done much testing for this.

The deprecation warnings about 'extra_lib_dirs' must be from a new version of JModelica that the introductory tutorial tests does not anticipate.  

Similarly, it looks like your results are slightly different than what is anticipated by the tutorial test.  

Please, what version of JModelica are you running?  Also, what is the operating system and version you are running inside the docker container?

Best Regards, 

Dave

Ken Joo Yeap

unread,
Aug 28, 2018, 2:18:14 AM8/28/18
to MPCPy
Hey Dave, 

thanks for the fast reply. I have a virtual Machine running Ubuntu 16.04 as suggested in the User guide, the JModelica version is the one from https://svn.jmodelica.org/trunk/ - I guess that's the newest version? Python is 2.7 as suggested in Userguide as well. 

Thanks! 

Regards, 
Ken

dhb...@gmail.com

unread,
Aug 28, 2018, 3:29:22 AM8/28/18
to MPCPy
Hey Ken, 

Thanks for the information.  Are you running any parallel processing?

Best Regards, 

Dave

Ken Joo Yeap

unread,
Aug 28, 2018, 4:19:52 AM8/28/18
to MPCPy
Hey Dave,

Thanks for the fast reply.

No, I have the VM solely for running MPCPy.

Regards,
Ken

David Blum

unread,
Sep 4, 2018, 1:57:05 PM9/4/18
to MPCPy
Hey Ken, 

I have installed the latest trunk of JModelica (as of 9/4/2018) and reproduced the errors regarding the tutorial tests you posted, which seem to be small numeric differences that are just outside the tolerance of the tests and also a deprecation warning.  I will make an issue in MPCPy to deal with this JModelica update.

Best Regards, 

Dave

Annie Mroz

unread,
Jun 17, 2019, 5:19:40 PM6/17/19
to MPCPy
I'm excited to try out the MPCPy toolbox, but having similar issues as Ken. I was having trouble installing JModelica on Linux so I used Tom Stesco's docker container and now that I figured that all out, JModelica seems to be working great https://github.com/TStesco/docker-jmodelica-env

Now I'm trying to run the introductory.py example and getting 25 errors (see attached).

I'm running Ubuntu 18.04.

Any thoughts or ideas how to get the toolbox to run? thanks!
Annie

dhb...@gmail.com

unread,
Jun 17, 2019, 5:28:30 PM6/17/19
to MPCPy
Hey Annie, 

I'm glad you are trying out MPCPy.  I am having trouble seeing the errors you mention.  Can you double check that you have attached your error output to the message?

Thanks!

Dave

Annie Mroz

unread,
Jun 17, 2019, 6:32:32 PM6/17/19
to MPCPy
Google Groups is not letting me add an attachment. I emailed you the attachment directly, but just in case you didn't receive, here's the error list: 
**********************************************************************
File "introductory.py", line 167, in __main__
Failed example:
    weather.collect_data(start_time, final_time) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[24]>", line 1, in <module>
        weather.collect_data(start_time, final_time) # doctest: +ELLIPSIS
      File "/opt/MPCPy/mpcpy/exodata.py", line 302, in collect_data
        self._collect_data(start_time, final_time);
      File "/opt/MPCPy/mpcpy/exodata.py", line 921, in _collect_data
        self._read_timeseries_from_epw();
      File "/opt/MPCPy/mpcpy/exodata.py", line 991, in _read_timeseries_from_epw
        time_ambiguous = pd.to_datetime(time_ambiguous.args[0].split("'")[1])
      File "/usr/local/lib/python2.7/dist-packages/pandas/core/tools/datetimes.py", line 611, in to_datetime
        result = convert_listlike(np.array([arg]), box, format)[0]
      File "/usr/local/lib/python2.7/dist-packages/pandas/core/tools/datetimes.py", line 302, in _convert_listlike_datetimes
        allow_object=True)
      File "/usr/local/lib/python2.7/dist-packages/pandas/core/arrays/datetimes.py", line 1866, in objects_to_datetime64ns
        raise e
    ValueError: (u'Unknown string format:', 'ambiguous')

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/opt/JModelica/Python/pymodelica/compiler_logging.py", line 218, in run
    xml.sax.parse(self.stream, LogErrorParser(self.result))
  File "/usr/lib/python2.7/xml/sax/__init__.py", line 33, in parse
    parser.parse(source)
  File "/usr/lib/python2.7/xml/sax/expatreader.py", line 116, in parse
    self._close_source()
  File "/usr/lib/python2.7/xml/sax/expatreader.py", line 235, in _close_source
    file.close()
AttributeError: KeepLastStream instance has no attribute 'close'

**********************************************************************
File "introductory.py", line 228, in __main__
Failed example:
    emulation = systems.EmulationFromFMU(measurements,
                                         moinfo = moinfo,
                                         weather_data = weather.data,
                                         control_data = control.data,
                                         tz_name = weather.tz_name)
Expected nothing
Got:
    Warning: The option 'extra_lib_dirs' has been deprecated and will be removed. Please use the 'file_name' to pass additional libraries.
/opt/MPCPy/mpcpy/utility.py:145: FutureWarning: The default of the 'keep_tz' keyword will change to True in a future release. You can set 'keep_tz=True' to obtain the future behaviour and silence this warning.
  t = df.index.to_series();
**********************************************************************
File "introductory.py", line 243, in __main__
Failed example:
    emulation.display_measurements('Measured').applymap('{:.2f}'.format) # doctest: +ELLIPSIS
Expected:
                                 Qflow   Tzone
    Time                                      
    2017-01-01 06:00:00+00:00  3000.00  293.15
    2017-01-01 07:00:00+00:00  3000.00  291.01
    2017-01-01 08:00:00+00:00  3000.00  291.32
    -etc-
Got:
                                 Qflow   Tzone
    Time                                      
    2017-01-01 06:00:00+00:00  3000.00  293.15
    2017-01-01 07:00:00+00:00  3000.00   37.19
    2017-01-01 08:00:00+00:00  3000.00   30.20
    2017-01-01 09:00:00+00:00  3000.00   30.01
    2017-01-01 10:00:00+00:00  3000.00   30.00
    2017-01-01 11:00:00+00:00  3000.00   30.00
    2017-01-01 12:00:00+00:00  3000.00   30.00
    2017-01-01 13:00:00+00:00  3000.00   30.00
    2017-01-01 14:00:00+00:00  3000.00   30.00
    2017-01-01 15:00:00+00:00  3000.00   30.00
    2017-01-01 16:00:00+00:00  3000.00   30.00
    2017-01-01 17:00:00+00:00  3000.00   30.00
    2017-01-01 18:00:00+00:00  3000.00   30.00
    2017-01-01 19:00:00+00:00  3000.00   30.00
    2017-01-01 20:00:00+00:00  3000.00   30.00
    2017-01-01 21:00:00+00:00  3000.00   30.00
    2017-01-01 22:00:00+00:00  3000.00   30.00
    2017-01-01 23:00:00+00:00  3000.00   30.00
    2017-01-02 00:00:00+00:00  3000.00   30.00
    2017-01-02 01:00:00+00:00  3000.00   30.00
    2017-01-02 02:00:00+00:00  3000.00   30.00
    2017-01-02 03:00:00+00:00  3000.00   30.00
    2017-01-02 04:00:00+00:00  3000.00   30.00
    2017-01-02 05:00:00+00:00  3000.00   30.00
    2017-01-02 06:00:00+00:00  3000.00   30.00
**********************************************************************
File "introductory.py", line 259, in __main__
Failed example:
    from mpcpy import models
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[35]>", line 1, in <module>
        from mpcpy import models
      File "/opt/MPCPy/mpcpy/models.py", line 77, in <module>
        import pyDOE as doe
    ImportError: No module named pyDOE
**********************************************************************
File "introductory.py", line 301, in __main__
Failed example:
    model = models.Modelica(models.JModelica,
                            models.RMSE,
                            emulation.measurements,
                            moinfo = moinfo,
                            parameter_data = parameters.data,
                            weather_data = weather.data,
                            control_data = control.data,
                            tz_name = weather.tz_name)
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[39]>", line 1, in <module>
        model = models.Modelica(models.JModelica,
    NameError: name 'models' is not defined
**********************************************************************
File "introductory.py", line 315, in __main__
Failed example:
    model.simulate('1/1/2017', '1/2/2017') # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[40]>", line 1, in <module>
        model.simulate('1/1/2017', '1/2/2017') # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 318, in __main__
Failed example:
    model.display_measurements('Simulated').applymap('{:.2f}'.format) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[41]>", line 1, in <module>
        model.display_measurements('Simulated').applymap('{:.2f}'.format) # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 334, in __main__
Failed example:
    model.estimate('1/1/2017', '1/2/2017', ['Tzone']) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[42]>", line 1, in <module>
        model.estimate('1/1/2017', '1/2/2017', ['Tzone']) # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 344, in __main__
Failed example:
    model.validate('1/1/2017', '1/2/2017', 'validate_tra', plot=1) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[43]>", line 1, in <module>
        model.validate('1/1/2017', '1/2/2017', 'validate_tra', plot=1) # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 347, in __main__
Failed example:
    print("%.3f" % model.RMSE['Tzone'].display_data()) # doctest: +NORMALIZE_WHITESPACE
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[44]>", line 1, in <module>
        print("%.3f" % model.RMSE['Tzone'].display_data()) # doctest: +NORMALIZE_WHITESPACE
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 359, in __main__
Failed example:
    model.measurements = emulation.measurements
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[48]>", line 1, in <module>
        model.measurements = emulation.measurements
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 361, in __main__
Failed example:
    model.validate(start_time_val, final_time_val, 'validate_val', plot=1) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[49]>", line 1, in <module>
        model.validate(start_time_val, final_time_val, 'validate_val', plot=1) # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 364, in __main__
Failed example:
    print("%.3f" % model.RMSE['Tzone'].display_data()) # doctest: +NORMALIZE_WHITESPACE
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[50]>", line 1, in <module>
        print("%.3f" % model.RMSE['Tzone'].display_data()) # doctest: +NORMALIZE_WHITESPACE
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 369, in __main__
Failed example:
    for key in model.parameter_data.keys():
        print(key, "%.2f" % model.parameter_data[key]['Value'].display_data())
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[51]>", line 1, in <module>
        for key in model.parameter_data.keys():
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 431, in __main__
Failed example:
    opt_problem = optimization.Optimization(model, 
                                            optimization.EnergyMin,
                                            optimization.JModelica,
                                            'Qflow',
                                            constraint_data = constraints.data)
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[57]>", line 1, in <module>
        opt_problem = optimization.Optimization(model,
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 449, in __main__
Failed example:
    opt_problem.optimize('1/2/2017', '1/3/2017') # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[58]>", line 1, in <module>
        opt_problem.optimize('1/2/2017', '1/3/2017') # doctest: +ELLIPSIS
    NameError: name 'opt_problem' is not defined
**********************************************************************
File "introductory.py", line 455, in __main__
Failed example:
    opt_problem.get_optimization_statistics() # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[59]>", line 1, in <module>
        opt_problem.get_optimization_statistics() # doctest: +ELLIPSIS
    NameError: name 'opt_problem' is not defined
**********************************************************************
File "introductory.py", line 462, in __main__
Failed example:
    opt_problem.display_measurements('Simulated').applymap('{:.2f}'.format) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[60]>", line 1, in <module>
        opt_problem.display_measurements('Simulated').applymap('{:.2f}'.format) # doctest: +ELLIPSIS
    NameError: name 'opt_problem' is not defined
**********************************************************************
File "introductory.py", line 475, in __main__
Failed example:
    model.control_data['Qflow'].display_data().loc[pd.to_datetime('1/2/2017  06:00:00'):pd.to_datetime('1/3/2017 06:00:00')].map('{:.2f}'.format) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[61]>", line 1, in <module>
        model.control_data['Qflow'].display_data().loc[pd.to_datetime('1/2/2017  06:00:00'):pd.to_datetime('1/3/2017 06:00:00')].map('{:.2f}'.format) # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 481, in __main__
Failed example:
    model.simulate('1/2/2017', '1/3/2017') # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[62]>", line 1, in <module>
        model.simulate('1/2/2017', '1/3/2017') # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 483, in __main__
Failed example:
    model.display_measurements('Simulated').applymap('{:.2f}'.format) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[63]>", line 1, in <module>
        model.display_measurements('Simulated').applymap('{:.2f}'.format) # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 500, in __main__
Failed example:
    opt_problem.optimize('1/2/2017', '1/3/2017', res_control_step=1.0) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[64]>", line 1, in <module>
        opt_problem.optimize('1/2/2017', '1/3/2017', res_control_step=1.0) # doctest: +ELLIPSIS
    NameError: name 'opt_problem' is not defined
**********************************************************************
File "introductory.py", line 502, in __main__
Failed example:
    model.control_data['Qflow'].display_data().loc[pd.to_datetime('1/2/2017 06:00:00'):pd.to_datetime('1/3/2017 06:00:00')].map('{:.2f}'.format) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[65]>", line 1, in <module>
        model.control_data['Qflow'].display_data().loc[pd.to_datetime('1/2/2017 06:00:00'):pd.to_datetime('1/3/2017 06:00:00')].map('{:.2f}'.format) # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 507, in __main__
Failed example:
    model.simulate('1/2/2017', '1/3/2017') # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[66]>", line 1, in <module>
        model.simulate('1/2/2017', '1/3/2017') # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
File "introductory.py", line 509, in __main__
Failed example:
    model.display_measurements('Simulated').applymap('{:.2f}'.format) # doctest: +ELLIPSIS
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[67]>", line 1, in <module>
        model.display_measurements('Simulated').applymap('{:.2f}'.format) # doctest: +ELLIPSIS
    NameError: name 'model' is not defined
**********************************************************************
1 items had failures:
  25 of  68 in __main__
***Test Failed*** 25 failures.

Tutorial finished with 25 fails.

David Blum

unread,
Jun 18, 2019, 9:07:15 AM6/18/19
to MPCPy
Hey Annie, 

Thanks for sending along the error outputs.  Try the following two things:

1. Use version 0.22 of the pandas python package.
2. Install the pyDOE python package.

Best Regards, 

Dave

Annie Mroz

unread,
Jun 18, 2019, 2:05:39 PM6/18/19
to MPCPy
Hi Dave,

Thanks for your help. I downgraded pandas and installed pyDOE per your instructions, and I think MPCPy is working ok, but I'm still getting 9 fails when I run the introductory.py script.

They look like  small numeric errors, similar to the ones that you mentioned above. See attached as an FYI.

Annie
introduction errors2.py

David Blum

unread,
Jun 18, 2019, 3:05:20 PM6/18/19
to MPCPy
Hey Annie, 

Great.  Yes, it looks like MPCPy is working.  The fails you are getting are indeed small numeric differences, though they are outside the tolerance I tried to set up in the doctests by reporting only up to two decimal places.  What version of JModelica are using?

Best Regards, 

Dave

Annie Mroz

unread,
Jun 18, 2019, 4:35:37 PM6/18/19
to MPCPy
I believe I installed the latest trunk yesterday which looks like v2.2 rev 12950.

dhb...@gmail.com

unread,
Jun 18, 2019, 5:17:34 PM6/18/19
to MPCPy
Thanks Annie.

The test results were generated with v2.0.  As the latest JModelica release is 2.4, I think the latest trunk would be a version of this, rather than v2.2.

Best Regards, 

Dave
Reply all
Reply to author
Forward
0 new messages