迭代优化中途失败,错误为AttributeError:“Series”对象没有属性“is_常量”

2024-09-30 10:35:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是运行一个能源系统优化(LP),它在30个时间步内迭代地以最佳方式改变能源系统成本。我可以先改变一些参数,比如二氧化碳价格,然后改变整个模型的输入数据。现在,该模型在较低的二氧化碳价格下完美地完成了它的工作,但当我提高价格时,迭代在某个时间步失败。在每一个时间步,模型都会通过更改可变组件进行更新,然后进行求解(使用Gurobi)

这是我收到的输出:

Using license file /home/fr/fr_fr/fr_sb838/gurobi.lic
DONE: dispatch, year: 2020, objective: cost
DONE: pathway_expansion, year: 2020, objective: cost
DONE: pathway_expansion, year: 2021, objective: cost
DONE: pathway_expansion, year: 2022, objective: cost
DONE: pathway_expansion, year: 2023, objective: cost
DONE: pathway_expansion, year: 2024, objective: cost
DONE: pathway_expansion, year: 2025, objective: cost
DONE: pathway_expansion, year: 2026, objective: cost
DONE: pathway_expansion, year: 2027, objective: cost
Traceback (most recent call last):
  File "/pfs/work7/workspace/scratch/fr_sb838-hiwi-0/simulation_2045/Master-Thesis-Robin-Krekeler/scripts/main.py", line 86, in <module>
    system.pathway_transmission_linear_expansion(join(result_dir, 'pathway_expansion_cost'), scenario)
  File "/pfs/work7/workspace/scratch/fr_sb838-hiwi-0/simulation_2045/Master-Thesis-Robin-Krekeler/scripts/optimisation.py", line 1028, in pathway_transmission_linear_expansion
    result = OPT.solve(model, warmstart=True)
  File "/home/fr/fr_fr/fr_sb838/.local/lib/python3.9/site-packages/pyomo/solvers/plugins/solvers/direct_solver.py", line 119, in solve
    self._presolve(*args, **kwds)
  File "/home/fr/fr_fr/fr_sb838/.local/lib/python3.9/site-packages/pyomo/solvers/plugins/solvers/direct_solver.py", line 62, in _presolve
    self._set_instance(model, kwds)
  File "/home/fr/fr_fr/fr_sb838/.local/lib/python3.9/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 251, in _set_instance
    self._add_block(model)
  File "/home/fr/fr_fr/fr_sb838/.local/lib/python3.9/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 268, in _add_block
    DirectOrPersistentSolver._add_block(self, block)
  File "/home/fr/fr_fr/fr_sb838/.local/lib/python3.9/site-packages/pyomo/solvers/plugins/solvers/direct_or_persistent_solver.py", line 237, in _add_block
    self._set_objective(obj)
  File "/home/fr/fr_fr/fr_sb838/.local/lib/python3.9/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 406, in _set_objective
    gurobi_expr, referenced_vars = self._get_expr_from_pyomo_expr(obj.expr, self._max_obj_degree)
  File "/home/fr/fr_fr/fr_sb838/.local/lib/python3.9/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 191, in _get_expr_from_pyomo_expr
    repn = generate_standard_repn(expr, quadratic=True)
  File "pyomo/repn/standard_repn.pyx", line 372, in pyomo.repn.standard_repn.generate_standard_repn
  File "pyomo/repn/standard_repn.pyx", line 998, in pyomo.repn.standard_repn._generate_standard_repn
  File "/home/fr/fr_fr/fr_sb838/.local/lib/python3.9/site-packages/pandas/core/generic.py", line 5465, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'is_constant'

我现在尝试了几种方法:

  • 将输入更改为明显不可行的条件。错误信息是完全不同的,我相当确信,问题对于每个时间步都是可行的
  • 在解算行之前,为每一步保存.lp文件。2027年前我会有一个。失败的时间步,.lp文件为空
  • 由于使用numpy数组(https://github.com/Pyomo/pyomo/issues/611)初始化索引参数时出现问题,我检查了所有初始化参数的格式,并将它们转换为字典
  • 在第998行pyomo.repn.standard_repn中的函数“_generate_standard_repn”中,我注释掉了elif:val.is_constant(),它似乎要求val对象具有这样的方法。但很明显,在这个例子中,瓦尔是一个熊猫系列,它不应该是。因此,下一个错误是TypeError:无法将序列转换为<;类“float”>;。因此,似乎有一个系列,尽管它不应该在那里。(顺便说一句,我是从github分叉pyomo rep,更改代码,然后从我自己的git repo安装pyomo的)

我正在使用pyomo6.0.1和pandas1.3.1(在一个带有Red Hat Enterprise Linux 8.2(Ootpa)的集群上)。我从Pyomo5.7.3和pandas 1.3.1(在一台装有Ubuntu20.04.1 LTS的机器上)收到了相同的错误。或者是pyomo5.6.9和pandas0.24.0的组合(在一台装有ubuntu18.04.5lts的机器上)

我非常感谢任何关于如何尝试解决问题的建议,提前谢谢大家


Tags: inpyhomelinefrfilepyomocost

热门问题