Exception: This steady-state IMODE only allows scalar values.

214 views
Skip to first unread message

براءة احمد

unread,
Jun 15, 2019, 2:08:10 PM6/15/19
to apmonitor
  ( I am trying to solve the following project (find in the link HERE
It throw the error in the picture 

Capture6.JPG

what is wrong ? how should I solve it?

John Hedengren

unread,
Jun 15, 2019, 2:31:11 PM6/15/19
to APM Google Groups
Dear Bara'a,

The problem is with the Parameter definition:

#Parameters Definition
TranCI  = m.Param(value=[14.2,10.635,17.725,14.18,28.36,14.2,17.725,10.635,17.725,\
21.27,17.725,24.815,14.18,21.27,22.1,24.815,14.18,14.18,17.725,21.27,16.4,10.635,\
21.27,24.815,15.9,38.995,21.27,14.7,15.6,21.27,17.725,28.36,21.27,21.27,28.36,17.725])
TCp     = m.Param(value=[70.3, 108.01, 36.01])   #unit_production_cost
SCj     = m.Param(value=[100000 , 285000])       #Storage_Capacity
PCp     = m.Param(value=[58330,29165,16665])     #Production_Capacity

One easy fix for this is to define the parameters a Numpy arrays instead of as Gekko arrays.

#Parameters Definition
TranCI  = np.array([14.2,10.635,17.725,14.18,28.36,14.2,17.725,10.635,17.725,\
21.27,17.725,24.815,14.18,21.27,22.1,24.815,14.18,14.18,17.725,21.27,16.4,10.635,\
21.27,24.815,15.9,38.995,21.27,14.7,15.6,21.27,17.725,28.36,21.27,21.27,28.36,17.725])
TCp     = np.array([70.3, 108.01, 36.01])   #unit_production_cost
SCj     =  np.array([100000 , 285000])       #Storage_Capacity
PCp     =  np.array([58330,29165,16665])     #Production_Capacity

Gekko expects each value (Parameter or Variable) to have a single value with IMODE = 1 or 3. You don't have a dynamic optimization problem so IMODE >=4 isn't appropriate for your application. https://gekko.readthedocs.io/en/latest/imode.html When you declare TranCI and other parameters as Numpy arrays then the values for TranCI[i] are substituted as numbers into the equation expressions.

-John Hedengren


--
--
APMonitor user's group e-mail list.
- To post a message, send email to apmo...@googlegroups.com
- To unsubscribe, send email to apmonitor+...@googlegroups.com
- Visit this group at http://groups.google.com/group/apmonitor
---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmonitor+...@googlegroups.com.
To post to this group, send email to apmo...@googlegroups.com.
Visit this group at https://groups.google.com/group/apmonitor.
To view this discussion on the web visit https://groups.google.com/d/msgid/apmonitor/53b2d5c2-d496-41d7-a035-15cffa6e5626%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Best regards,

John Hedengren
APMonitor Optimization Suite

براءة احمد

unread,
Jun 16, 2019, 9:15:15 AM6/16/19
to apmonitor
If gekko don't accept the variable to be more than a single value I will have the arror again I guess, as my variables are arrays too.
Should i change the variable too as np.array?

John Hedengren

unread,
Jun 16, 2019, 9:24:40 AM6/16/19
to APM Google Groups
If you need an array of variables or parameters then it is easiest to use the m.Array function as:

x = m.Array(m.Var,4,lb=0,ub=1)

The values can then be used in equations such as:

m.Equations([x[i+1] = x[i]+2 for i in range(3)])

You should replace the dimension 4 with the size that you'd like. If you need a multiple dimensional array then it should be (4,3).

If you need to declare parameters with an initial value then here is an example:

p = m.Array(m.Param,10)
for i in range(10):
    p[i].value = i**2

Additional information is in the documentation: https://gekko.readthedocs.io/en/latest/model_methods.html

-John Hedengren

‪On Sun, Jun 16, 2019 at 7:15 AM ‫براءة احمد‬‎ <bara2a....@gmail.com> wrote:‬
If gekko don't accept the variable to be more than a single value I will have the arror again I guess, as my variables are arrays too.
Should i change the variable too as np.array?

--
--
APMonitor user's group e-mail list.
- To post a message, send email to apmo...@googlegroups.com
- To unsubscribe, send email to apmonitor+...@googlegroups.com
- Visit this group at http://groups.google.com/group/apmonitor
---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmonitor+...@googlegroups.com.
To post to this group, send email to apmo...@googlegroups.com.
Visit this group at https://groups.google.com/group/apmonitor.

For more options, visit https://groups.google.com/d/optout.

براءة احمد

unread,
Jun 17, 2019, 8:04:08 AM6/17/19
to apmonitor
 thanks a lot for the helpfull responce 
I have changed the  
parameters as u say and it worked but an other error had pop up unfortunately 

Capture6.JPG

showen in the pic 
will u plz givee me any recomendation 
the code after changes HERE 

John Hedengren

unread,
Jun 18, 2019, 12:11:26 PM6/18/19
to APM Google Groups
The model file is the .apm file that you'll find in the temp folder. This folder can be accessed with m.open_folder(). The model file is written when you give the m.solve() command so you'll need to run m.open_folder() after the error occurs.

One thing to try is to give a name to each of your parameters and variables. It will make your error more readable and can help you identify where the error is coming from:

for j in range (24):
  Xt[j].value = 20
  Xt[j].lower = 0
  Xt[j].upper = 100000000
  Xt[j].name = 'xt['+str(j)+']' 
for i in range(3):
  for j in range(24):
    Xpt[i,j].value = 20
    Xpt[i,j].lower = 0
    Xpt[i,j].upper = 100000000
    Xpt[i,j].name = f'xt[{i}][{j}]' # formatted string

My best guess based on seeing p3 (third parameter = Yp) in the expression is that there is a problem with:

#Defining Equations
XtYp   = [None] * 24
for i in range (24):
  XtYp[i] = (m.Intermediate ([Xt[i] * Yp]) )


Maybe it doesn't like the extra brackets and parenthesis that make the internal part a list:

#Defining Equations
XtYp   = [None] * 24
for i in range (24):
  XtYp[i] = m.Intermediate (Xt[i] * Yp)

There is additional debugging help with video #18 in this list:


Best regards,
John Hedengren

--
--
APMonitor user's group e-mail list.
- To post a message, send email to apmo...@googlegroups.com
- To unsubscribe, send email to apmonitor+...@googlegroups.com
- Visit this group at http://groups.google.com/group/apmonitor
---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmonitor+...@googlegroups.com.
To post to this group, send email to apmo...@googlegroups.com.
Visit this group at https://groups.google.com/group/apmonitor.

For more options, visit https://groups.google.com/d/optout.

براءة احمد

unread,
Jun 18, 2019, 12:12:10 PM6/18/19
to apmonitor
Dr John 
Pls help me find the solution of the error mentioned previously. 

Bara'a Ahmad.
Industrial Engineer.
Engineer at Ministry of Energy and Miniral Resources.
Amman, Jordan
Zip code 11623.
+962791410153.
Bara2a....@gmail.com.

--

John Hedengren

unread,
Jun 18, 2019, 12:39:45 PM6/18/19
to apmo...@googlegroups.com

I apologize for the delay. My messages are sometimes flagged as spam when I include links and it needed to be approved by the moderation system. I hope that message helps with debugging.


-John Hedengren


From: apmo...@googlegroups.com <apmo...@googlegroups.com> on behalf of براءة احمد <bara2a....@gmail.com>
Sent: Tuesday, June 18, 2019 10:08 AM
To: apmonitor
Subject: Re: [APM] Re: Exception: This steady-state IMODE only allows scalar values.
 

براءة احمد

unread,
Jun 18, 2019, 6:53:05 PM6/18/19
to apmonitor
Dr. John 
Thanks for your help, I really approciate it 
will you plz help me with this erro, shown in the pic

Capture11.JPG



بتاريخ الثلاثاء، 18 يونيو، 2019 7:39:45 م UTC+3، كتب John Hedengren:

I apologize for the delay. My messages are sometimes flagged as spam when I include links and it needed to be approved by the moderation system. I hope that message helps with debugging.


-John Hedengren


From: apmo...@googlegroups.com <apmo...@googlegroups.com> on behalf of براءة احمد <bara2a...@gmail.com>

Sent: Tuesday, June 18, 2019 10:08 AM
To: apmonitor
Subject: Re: [APM] Re: Exception: This steady-state IMODE only allows scalar values.
 
Dr John 
Pls help me find the solution of the error mentioned previously. 

Bara'a Ahmad.
Industrial Engineer.
Engineer at Ministry of Energy and Miniral Resources.
Amman, Jordan
Zip code 11623.
+962791410153.
On Mon, 17 Jun 2019, 15:04 براءة احمد, <bara2a...@gmail.com> wrote:
 thanks a lot for the helpfull responce 
I have changed the  
parameters as u say and it worked but an other error had pop up unfortunately 

Capture6.JPG

showen in the pic 
will u plz givee me any recomendation 
the code after changes HERE 
 
 
 
  

بتاريخ السبت، 15 يونيو، 2019 9:08:10 م UTC+3، كتب براءة احمد:
  ( I am trying to solve the following project (find in the link HERE
It throw the error in the picture 

Capture6.JPG

what is wrong ? how should I solve it?

--
--
APMonitor user's group e-mail list.
- To post a message, send email to apmo...@googlegroups.com
- To unsubscribe, send email to apmo...@googlegroups.com

- Visit this group at http://groups.google.com/group/apmonitor
---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmo...@googlegroups.com.

--
--
APMonitor user's group e-mail list.
- To post a message, send email to apmo...@googlegroups.com
- To unsubscribe, send email to apmo...@googlegroups.com

- Visit this group at http://groups.google.com/group/apmonitor
---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmo...@googlegroups.com.

John Hedengren

unread,
Jun 18, 2019, 7:32:07 PM6/18/19
to APM Google Groups
One of your equations is beyond the 15,000 character limit for a single line. You can find which equation is over the limit by opening the run folder:

m.open_folder()

and open the .apm file with a text editor such as Notepad++. If you need help on showing file extensions, here is a video: https://youtu.be/YlN9ax7yC0A  The apm file will show which equation is very long. If you've named your variables then the raw model file will be easier to understand.

One way to break up the equations is to use the m.Intermediate() function. Below is an example:

x = m.Var(name='x')
m.Equations(0.1*x+0.2*x+0.3*x == 0.4*x + 0.5*x + 0.6*x)

This can be divided into Intermediates with something like the following:

x = m.Var()
y = m.Intermediate(0.1*x+0.2*x+0.3*x)
z = m.Intermediate(0.4*x + 0.5*x + 0.6*x)
m.Equation(y==z)

-John Hedengren


- To unsubscribe, send email to apmonitor+...@googlegroups.com

- Visit this group at http://groups.google.com/group/apmonitor
---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmonitor+...@googlegroups.com.

To post to this group, send email to apmo...@googlegroups.com.
Visit this group at https://groups.google.com/group/apmonitor.

For more options, visit https://groups.google.com/d/optout.


--

براءة احمد

unread,
Jun 19, 2019, 7:37:51 AM6/19/19
to apmo...@googlegroups.com
About the variables naming, it gave me an error that "variable don't have this attribute".
Any suggestions!

Bara'a Ahmad.
Industrial Engineer.
Engineer at Ministry of Energy and Miniral Resources.
Amman, Jordan
Zip code 11623.
+962791410153.

John Hedengren

unread,
Jun 19, 2019, 3:30:35 PM6/19/19
to apmo...@googlegroups.com

Dear Bara'a,

 

Below is an example of naming a variable:

 

from gekko import GEKKO

m = GEKKO()            # create GEKKO model

x = m.Var(name='x')    # define new variable, default=0

y = m.Var()            # define new variable, default=0

m.Equations([3*x+2*y==1, x+2*y==0])  # equations

m.solve(disp=True)    # solve

m.open_folder()

print(x.value,y.value) # print solution

 

When the folder opens, I also open the .apm file to show that the model file uses the name ‘x’ for one of the variables and ‘v2’ for the other variable. It is ‘v2’ because I don’t assign a name.

 

Model

Variables

      x = 0

      v2 = 0

End Variables

Equations

      (((3)*(x))+((2)*(v2)))=1

      (x+((2)*(v2)))=0

End Equations

End Model

 

If you are still running into a problem, I recommend that you check the property name or anything else that may be a syntax issue. For better support on issues that you encounter, please include a simple and complete example (such as the one above) that demonstrates the issue that you are trying to solve. These simple examples help me with debugging my own applications as well.

 

Best regards,

John Hedengren

Image removed by sender. Capture6.JPG

showen in the pic 

will u plz givee me any recomendation 

the code after changes HERE 

 

 

 

  


بتاريخ السبت، 15 يونيو، 2019 9:08:10 م UTC+3، كتب براءة احمد:

  ( I am trying to solve the following project (find in the link HERE

It throw the error in the picture 

Image removed by sender. Capture6.JPG

براءة احمد

unread,
Jun 23, 2019, 7:04:39 PM6/23/19
to apmonitor
what do you think the problem with this error

‫في الأربعاء، 19 يونيو 2019 في 10:30 م تمت كتابة ما يلي بواسطة ‪John Hedengren‬‏ <‪john_he...@byu.edu‬‏>:‬

For more options, visit https://groups.google.com/d/optout.


--

Bara’a Al-Suradi


Industrial Engineer.

Planning Engineer at Ministry of Energy and Mineral Resources .


Al-Bnyat , Airport street

Amman,Jordan.


 0791410153


Bara2a....@gmail.com


https://goo.gl/tujXk9

https://goo.gl/cNyPY8

https://goo.gl/Uq6GND

.


Wherever Allah puts you, you should succeed.


Capture111.JPG

John Hedengren

unread,
Jun 24, 2019, 2:25:34 PM6/24/19
to apmonitor

Some of your values that you are using as an input are strings (type:<U32). Here is example code that shows what the <U32 type looks like when you print it:


import numpy as np
y = np.array([1.8, 1.9, 2.4], dtype='<U32')
print(y)
print(type(y[0]))

Result:

['1.8' '1.9' '2.4']
<class 'numpy.str_'>​

Make sure that the inputs to your model are numbers, not strings. The specific error says that you have a string of 3 that it is trying to multiply by np.ones(1).

-John Hedengren




From: apmo...@googlegroups.com <apmo...@googlegroups.com> on behalf of براءة احمد <bara2a....@gmail.com>
Sent: Sunday, June 23, 2019 2:48 PM
Reply all
Reply to author
Forward
0 new messages