HiGHS求解器用于PyPSA-EUR

huangapple go评论102阅读模式
英文:

HiGHS solver for PyPSA-EUR

问题

我正在尝试在PyPSA-Eur中使用HiGHS求解器。通过在config.yaml中进行如下设置:

solver:
  name: highs
  options: {}

它会抛出以下错误:

> RuntimeError: 尝试使用不可用的求解器。
> 
> SolverFactory 无法创建求解器 "highs",并返回了一个 UnknownSolver 对象。此错误是在使用 UnknownSolver 对象作为有效对象(通过调用 "has_capability" 方法)的地方引发的。
> 
> 最初的求解器是以以下参数创建的:
>         executable: highs
>         type: highs
>         _args: ()
>         options: {}

在创建高级环境时,highspy被正确安装,没有任何问题。

而在pypsa-eur环境中,如果我运行 python -c "import highspy",它不会抛出任何错误,这意味着highspy已经可用于使用。

我们如何配置pypsa以使用HiGHS作为求解器?

英文:

I am trying to use HiGHS solver for PyPSA-Eur. By setting it in config.yaml like:

  solver:
    name: highs
    options: {}

It throws following error:

> RuntimeError: Attempting to use an unavailable solver.
>
> The SolverFactory was unable to create the solver "highs" and returned
> an UnknownSolver object. This error is raised at the point where the
> UnknownSolver object was used as if it were valid (by calling method
> "has_capability").
>
> The original solver was created with the following parameters:
> executable: highs
> type: highs
> _args: ()
> options: {}

while creating the environment highspy gets installed properly and no issues there.

While in the pypsa-eur environment if i do python -c "import highspy" it does not throw any error that means highspy is there to be used.

How can we configure pypsa to use HiGHS as a solver?

答案1

得分: 2

应该可以正常工作,如果你使用以下配置:

  solver:
    name: highs
    options: highs-default

第一行定义了求解器,第二行定义了用于求解器的选项。

英文:

It should work if you use

  solver:
    name: highs
    options: highs-default

First line defines the solver, second line defines the options to use for the solver.

答案2

得分: 1

如果您使用的是Windows,可能需要手动安装HiGHS二进制文件。不确定。

https://ergo-code.github.io/HiGHS/stable/installation/

英文:

Should you be on Windows, it might be that you have to install HiGHS binaries manually. Not sure.

https://ergo-code.github.io/HiGHS/stable/installation/

答案3

得分: 1

需要从https://github.com/ERGO-Code/HiGHS构建HiGHS,并且它起作用。还必须在LD_LIBRARY_PATH中包含HiGHS共享库路径,以便可以找到动态链接的库。

从源代码构建HiGHS后,可在以下位置找到可执行文件:

> <HiGHS-isntallation-dir>/HiGHS/build/bin/

可能需要创建符号链接或提供可执行文件的完整路径。

似乎HiGHS无法处理PyPSA-Eur中的网络聚类

如果不支持quadratic_objective&quot;):
        logger.warning(
            f&quot;配置的求解器`{solver_name}`不支持二次目标。回退到`ipopt`。&quot;
        )
        opt = po.SolverFactory(&quot;ipopt&quot;)
    
    results = opt.solve(m, tee=True)

在使用HiGHS时,在results = opt.solve(m, tee=True)处遇到了错误,因此作为一种解决方法,我默认使用ipopt来进行cluster_network规则(snakemake)并使用HiGHS来解决模型。

英文:

Had to build HiGHS from https://github.com/ERGO-Code/HiGHS and it worked. Also HiGHS shared lib path has to be included in LD_LIBRARY_PATH so the dynamically linked lib can be found.

After building HiGHS from source the executable can be found in:

> <HiGHS-isntallation-dir>/HiGHS/build/bin/

One might need to create a symlink or provide a complete path to the executable.

It seems that HiGHS was not able to handle network clustering in PyPSA-Eur

if not opt.has_capability(&quot;quadratic_objective&quot;):
        logger.warning(
            f&quot;The configured solver `{solver_name}` does not support quadratic objectives. Falling back to `ipopt`.&quot;
        )
        opt = po.SolverFactory(&quot;ipopt&quot;)
    
    results = opt.solve(m, tee=True)

When using HiGHS the error was encountered at results = opt.solve(m, tee=True) so as a workaround I used ipopt by default for cluster_network rule (snakemake) and used HiGHS to solve the model.

huangapple
  • 本文由 发表于 2023年8月4日 02:27:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76830747.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定