简体   繁体   English

如何查看 Gekko 变量/参数以进行调试?

[英]How to view Gekko variables/parameters for debug purposes?

I have a fitting task where I am using GEKKO.我有一个合适的任务,我正在使用 GEKKO。

There are a lot of variables, arrays of variables, some variables that must contain arrays, and so on.变量有很多,arrays个变量,有些变量必须包含arrays,等等。

I didn't have success with the fitting, so I need to do step-by-step verification of all parameters that I am providing for GEKKO and all the calculated intermediate values.我没有成功拟合,所以我需要对我为 GEKKO 提供的所有参数和所有计算的中间值进行逐步验证。

Is there a way to print out the values of each variable for debugging purposes?有没有办法打印出每个变量的值以进行调试? Or to view the values of the variables in line-by-line execution?还是逐行执行查看变量的值?

for example, I have an array that is saved like a variable ro :例如,我有一个像变量ro一样保存的数组:

phi = model.Intermediate( c * ro) # phase shift 

where c is some constant defined somewhere above in the model definition.其中 c 是 model 定义中某处定义的某个常量。

How can I view the values inside phi that will be used in the next steps?如何查看将在后续步骤中使用的 phi 中的值?

I need to view/save all the values of all variables/constants/intermediates used during the model creation - before a try to solve.在尝试解决之前,我需要查看/保存 model 创建期间使用的所有变量/常量/中间体的所有值。 Is it possible?可能吗?

Turn up the DIAGLEVEL to 2 or higher to produce diagnostic files in the run directory m.path .DIAGLEVEL至 2 或更高以在运行目录m.path中生成诊断文件。

from gekko import GEKKO
m = GEKKO(remote=False)
c = 2
x = m.Param(3,name='x')
ro = m.Var(value=4,lb=0,ub=10,name='ro')
y = m.Var()
phi = m.Intermediate(c*ro,name='phi')
m.Equation(y==phi**2+x)
m.Maximize(y)
m.options.SOLVER = 1
m.options.DIAGLEVEL=2
m.open_folder()
m.solve()

Here is a summary of the diagnostic files that are produced:以下是生成的诊断文件的摘要:

Variables, Equations, Jacobian, Lagrange Multipliers, Objective变量、方程、雅可比行列式、拉格朗日乘数、目标

  • apm_eqn.txt apm_eqn.txt
  • apm_jac.txt apm_jac.txt
  • apm_jac_fv.txt apm_jac_fv.txt
  • apm_lam.txt apm_lam.txt
  • apm_lbt.txt apm_lbt.txt文件
  • apm_obj.txt apm_obj.txt
  • apm_obj_grad.txt apm_obj_grad.txt
  • apm_var.txt apm_var.txt

Solver Output and Options求解器 Output 和选项

  • APOPT.out APOPT输出
  • apopt_current_options.opt apopt_current_options.opt

Model File Model 文件

  • gk_model0.apm gk_model0.apm

Data File数据文件

  • gk_model0.csv gk_model0.csv

Options Files选项文件

  • gk_model0.dbs gk_model0.dbs
  • options.json选项.json

Specification File for FV, MV, SV, CV FV、MV、SV、CV 规格文件

  • gk_model0.info gk_model0.info

Inputs to the Model输入到 Model

  • dbs_read.rpt dbs_read.rpt
  • input_defaults.dbs input_defaults.dbs
  • input_gk_model0.dbs input_gk_model0.dbs
  • input_measurements.dbs input_measurements.dbs
  • input_overrides.dbs input_overrides.dbs
  • measurements.dbs测量.dbs

Results结果

  • rto.t0 rto.t0
  • results.csv结果.csv
  • results.json结果.json
  • gk_model0_r_2022y12m04d08h12m28.509s.t0 gk_model0_r_2022y12m04d08h12m28.509s.t0

Initialization Steps Before Solve求解前的初始化步骤

  • rto_1.t0 rto_1.t0
  • rto_2.t0 rto_2.t0
  • rto_3.t0 rto_3.t0
  • rto_3_eqn.txt rto_3_eqn.txt
  • rto_3_eqn_var.txt rto_3_eqn_var.txt
  • rto_3_var.t0 rto_3_var.t0

Reports After Solve解决后的报告

  • rto_4.t0 rto_4.t0
  • rto_4_eqn.txt rto_4_eqn.txt
  • rto_4_eqn_var.txt rto_4_eqn_var.txt
  • rto_4_var.t0 rto_4_var.t0

The files of interest for you are likely the rto* initialization files.您感兴趣的文件可能是rto*初始化文件。 The name changes based on the IMODE that you run.名称会根据您运行的IMODE而更改。 It is mpu* for your application for a Model Parameter Update with IMODE=2 .它是mpu* ,适用于您使用 IMODE IMODE=2进行 Model 参数更新的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM