[英]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变量、方程、雅可比行列式、拉格朗日乘数、目标
Solver Output and Options求解器 Output 和选项
Model File Model 文件
Data File数据文件
Options Files选项文件
Specification File for FV, MV, SV, CV FV、MV、SV、CV 规格文件
Inputs to the Model输入到 Model
Results结果
Initialization Steps Before Solve求解前的初始化步骤
Reports After Solve解决后的报告
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.