【发布时间】:2020-03-12 07:24:19
【问题描述】:
我还没有看到与此相关的问题,尽管我做了几次相反的努力,但它还是弹出来了,所以我希望有人可以帮助我了解发生了什么。
我是 Python 的 Gekko 包的新手,我正在尝试运行一个非线性求解器来解决正在发生的事情。我收到一条奇怪的错误消息 (FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/03/vyh22j3j45j2rqjmnygfw2l80000gn/T/tmpatrk8y36gk_model0/options.json'),似乎是程序化/句法而不是数学。它是一个更大的函数/数据/输入中的一个函数,因此我很难提供足够的数据来帮助您复制它——但是——
y(即 self.get_days_energy(date = date) 的结果)是一个能量值向量,来自 self.get_exogenous_inputs_of_day(date) 的外生输入也是如此。 Z 变量是潜在状态变量,A 和 B 分别是潜在状态和外生变量的转移矩阵。此函数的目标是更新上述三个变量。
函数如下:
def daily_weight_fit(self, date):
"""
Update function to the weights of the dynamic system, this will be called
once a day after the data has arrived.
"""
m = GEKKO(remote = False)
A = m.Array(
m.Var,
(self.state_weights.shape),
value = 1,
lb = -10,
ub = 10,
)
B = m.Array(
m.Var,
(self.input_weights.shape),
value = 1,
lb = -100,
ub = 100,
)
dates = pd.date_range(start=self.starting_date, end=date)
date_list = dates.tolist()
hours = list(range(24))
y = [[self.get_days_energy(date = date)] for date in dates]
flat_y = np.reshape(y, -1)
timesteps = len(flat_y)
u = [self.get_exogenous_inputs_of_day(date) for date in dates for hour in hours]
z = m.Array(m.Var, (timesteps, 4), lb = -1, ub = 1)
C = np.array([0, 0, 1, 0])
m.Obj(
m.sqrt(
m.sum([(flat_y[i] - z[i][3])**2 for i in range(len(flat_y))])
)
)
for i in range(timesteps - 2):
state_contribution = np.dot(A, z[i])
ex_contribution = np.dot(B, u[i])
for j in range(4):
m.Equation(z[i + 1][j] == state_contribution[j] + ex_contribution[j])
m.options.solver = 1
m.solve()
return A, B, z
这是错误输出:
----------------------------------------------------------------
APMonitor, Version 0.9.2
APMonitor Optimization Suite
----------------------------------------------------------------
--------- APM Model Size ------------
Each time step contains
Objects : 1
Constants : 0
Variables : 1849
Intermediates: 0
Connections : 361
Equations : 1793
Residuals : 1793
Number of state variables: 1849
Number of total equations: - 1793
Number of slack variables: - 0
---------------------------------------
Degrees of freedom : 56
----------------------------------------------
Steady State Optimization with APOPT Solver
----------------------------------------------
Iter Objective Convergence
0 4.12076E+08 8.12928E+01
1 5.38520E+02 1.00000E+00
2 5.38512E+02 3.75145E-12
3 5.38450E+02 2.00000E+00
4 5.38506E+02 1.80710E-01
NEGATIVE NDF: -1
5 1.10270E+07 3.34638E-01
6 4.89845E+06 1.93472E+00
7 4.73333E+05 3.99952E+00
8 3.76178E+05 2.00000E+00
9 1.69753E+05 1.31302E+00
Iter Objective Convergence
10 1.90770E+07 5.86504E-01
11 3.03623E+16 3.34638E-01
12 9.38385E+11 3.34304E-01
13 1.14353E+12 1.09011E-02
14 8.91928E+12 7.65181E-03
Error:
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x108c7718d
#1 0x108c7661b
#2 0x7fff661ccf59
#3 0x108a92b6b
apm_mac(33870,0x7fff9e9c1380) malloc: *** error for object 0x7fb371862e00: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Program received signal SIGABRT: Process abort signal.
Backtrace for this error:
#0 0x108c7718d
#1 0x108c7661b
#2 0x7fff661ccf59
Error: 'results.json' not found. Check above for additional error details
Traceback (most recent call last):
.... (my own irrelevant function trace).....
m.solve()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gekko/gekko.py", line 2145, in solve
self.load_JSON()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gekko/gk_post_solve.py", line 13, in load_JSON
f = open(os.path.join(self._path,'options.json'))
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/03/vyh22j3j45j2rqjmnygfw2l80000gn/T/tmp42metzl9gk_model0/options.json'
任何提示或建议将不胜感激! John Hedengren,嗨,我喜欢你的工作!!
【问题讨论】:
-
感谢您的鼓励和提出的问题。
标签: python dynamic system gekko