Ubuntu 18.04 上的 JModelica
JModelica on Ubuntu 18.04
您好 JModelica 社区。我已经设法在 CentOS 上编译 JModelica,但我在 Ubuntu 18.04 上仍然失败。编译本身是成功的,但是运行
from pyjmi.examples import cstr_casadi
cstr_casadi.run_demo()
失败
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-33de447ae4ee> in <module>()
----> 1 cstr_casadi.run_demo()
/opt/JModelica.org/Python/pyjmi/examples/cstr_casadi.pyc in run_demo(with_plots)
179
180 # Solve the optimal control problem
--> 181 res = op.optimize(options=opt_opts)
182
183 # Extract variable profiles
/opt/JModelica.org/Python/pyjmi/casadi_interface.pyc in optimize(self, algorithm, options)
446 "algorithm.")
447 return self._exec_algorithm('pyjmi.jmi_algorithm_drivers',
--> 448 algorithm, options)
449
450 # Make solve synonymous with optimize
/opt/JModelica.org/Python/pyjmi/common/core.pyc in _exec_algorithm(self, module, algorithm, options)
166 alg = algorithm(self, options)
167 # solve optimization problem/initialize
--> 168 alg.solve()
169 # get and return result
170 return alg.get_result()
/opt/JModelica.org/Python/pyjmi/jmi_algorithm_drivers.pyc in solve(self)
351 Solve the optimization problem using ipopt solver.
352 """
--> 353 self.nlp.solve_and_write_result()
354
355 def get_result(self):
/opt/JModelica.org/Python/pyjmi/optimization/casadi_collocation.pyc in solve_and_write_result(self)
995 t0 = time.clock()
996 # todo: account for preprocessing time within solve_nlp separately?
--> 997 self.times['sol'] = self.solve_nlp()
998 self.result_file_name = self.export_result_dymola(self.result_file_name)
999 self.times['post_processing'] = time.clock() - t0 - self.times['sol'] - self.extra_update
/opt/JModelica.org/Python/pyjmi/optimization/casadi_collocation.pyc in solve_nlp(self)
610
611 # Get the result
--> 612 primal_opt = N.array(self.solver_object.output(casadi.NLP_SOLVER_X))
613 self.primal_opt = primal_opt.reshape(-1)
614 if self.order != "default":
/opt/JModelica.org/Python/casadi/casadi_core.pyc in <lambda>(self, name)
30560 for _s in [Function]:
30561 __swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
> 30562 __getattr__ = lambda self, name: _swig_getattr(self, NlpSolver, name)
30563 __repr__ = _swig_repr
30564
/opt/JModelica.org/Python/casadi/casadi_core.pyc in _swig_getattr(self, class_type, name)
78 if method:
79 return method(self)
---> 80 raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
81
82
AttributeError: 'NlpSolver' object has no attribute 'output'
我尝试降级了几个软件包,但问题仍然存在。我在 Arch Linux btw.
上有同样的错误
我知道 Ubuntu 18.04 没有得到官方支持,但我希望有人已经找到解决这个问题的方法。
编辑:
来自 make install
和 make casadi_interface
的日志:
您似乎加载了错误的 casadi 版本。
你能检查一下输出吗
from casadi import __version__
print(__version__)
编辑
可能与 swig 版本有关。
将 solver_object.output 替换为 solver_object.getOutput 应该会有帮助!
例如
primal_opt = N.array(self.solver_object.output(casadi.NLP_SOLVER_X))
和
primal_opt = N.array(self.solver_object.getOutput(casadi.NLP_SOLVER_X))
也许变更集:https://trac.jmodelica.org/changeset/8074
有助于文件和位置的概览。
我正在回答我自己的问题以将其标记为已解决。解决方案来自@Vital(见原问题的评论)。
为了让 JModelica 在 Ubuntu 18.04 或 Arch Linux 上工作,solver_object.output
需要在所有受影响的 Python 文件中替换为 solver_object.getOutput
。
我根据 Whosebug 上的贡献和原始的 JModelica 用户指南创建了一个 Linux 安装脚本。此安装脚本位于 https://gitlab.com/christiankral/install_jmodelica/.
您好 JModelica 社区。我已经设法在 CentOS 上编译 JModelica,但我在 Ubuntu 18.04 上仍然失败。编译本身是成功的,但是运行
from pyjmi.examples import cstr_casadi
cstr_casadi.run_demo()
失败
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-33de447ae4ee> in <module>()
----> 1 cstr_casadi.run_demo()
/opt/JModelica.org/Python/pyjmi/examples/cstr_casadi.pyc in run_demo(with_plots)
179
180 # Solve the optimal control problem
--> 181 res = op.optimize(options=opt_opts)
182
183 # Extract variable profiles
/opt/JModelica.org/Python/pyjmi/casadi_interface.pyc in optimize(self, algorithm, options)
446 "algorithm.")
447 return self._exec_algorithm('pyjmi.jmi_algorithm_drivers',
--> 448 algorithm, options)
449
450 # Make solve synonymous with optimize
/opt/JModelica.org/Python/pyjmi/common/core.pyc in _exec_algorithm(self, module, algorithm, options)
166 alg = algorithm(self, options)
167 # solve optimization problem/initialize
--> 168 alg.solve()
169 # get and return result
170 return alg.get_result()
/opt/JModelica.org/Python/pyjmi/jmi_algorithm_drivers.pyc in solve(self)
351 Solve the optimization problem using ipopt solver.
352 """
--> 353 self.nlp.solve_and_write_result()
354
355 def get_result(self):
/opt/JModelica.org/Python/pyjmi/optimization/casadi_collocation.pyc in solve_and_write_result(self)
995 t0 = time.clock()
996 # todo: account for preprocessing time within solve_nlp separately?
--> 997 self.times['sol'] = self.solve_nlp()
998 self.result_file_name = self.export_result_dymola(self.result_file_name)
999 self.times['post_processing'] = time.clock() - t0 - self.times['sol'] - self.extra_update
/opt/JModelica.org/Python/pyjmi/optimization/casadi_collocation.pyc in solve_nlp(self)
610
611 # Get the result
--> 612 primal_opt = N.array(self.solver_object.output(casadi.NLP_SOLVER_X))
613 self.primal_opt = primal_opt.reshape(-1)
614 if self.order != "default":
/opt/JModelica.org/Python/casadi/casadi_core.pyc in <lambda>(self, name)
30560 for _s in [Function]:
30561 __swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
> 30562 __getattr__ = lambda self, name: _swig_getattr(self, NlpSolver, name)
30563 __repr__ = _swig_repr
30564
/opt/JModelica.org/Python/casadi/casadi_core.pyc in _swig_getattr(self, class_type, name)
78 if method:
79 return method(self)
---> 80 raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
81
82
AttributeError: 'NlpSolver' object has no attribute 'output'
我尝试降级了几个软件包,但问题仍然存在。我在 Arch Linux btw.
上有同样的错误我知道 Ubuntu 18.04 没有得到官方支持,但我希望有人已经找到解决这个问题的方法。
编辑:
来自 make install
和 make casadi_interface
的日志:
您似乎加载了错误的 casadi 版本。 你能检查一下输出吗
from casadi import __version__
print(__version__)
编辑
可能与 swig 版本有关。
将 solver_object.output 替换为 solver_object.getOutput 应该会有帮助! 例如
primal_opt = N.array(self.solver_object.output(casadi.NLP_SOLVER_X))
和
primal_opt = N.array(self.solver_object.getOutput(casadi.NLP_SOLVER_X))
也许变更集:https://trac.jmodelica.org/changeset/8074 有助于文件和位置的概览。
我正在回答我自己的问题以将其标记为已解决。解决方案来自@Vital(见原问题的评论)。
为了让 JModelica 在 Ubuntu 18.04 或 Arch Linux 上工作,solver_object.output
需要在所有受影响的 Python 文件中替换为 solver_object.getOutput
。
我根据 Whosebug 上的贡献和原始的 JModelica 用户指南创建了一个 Linux 安装脚本。此安装脚本位于 https://gitlab.com/christiankral/install_jmodelica/.