AttributeError: 'Series' object has no attribute 'is_expression_type'

1,264 views
Skip to first unread message

Armaghan Bhr

unread,
Apr 23, 2020, 2:07:50 PM4/23/20
to Pyomo Forum
Enter code here...

I'm trying to calculate the temperature along a pipeline by using 2 for loops, one for time and one for different points along the pipe. and finally, I get (return) the outlet temperature of the pipe (which is at n_nodes=2500000 or the last point in self.block.all_x)

This is a part of my code:
            self.block.all_time = Set(initialize=range(n_steps), ordered=True)
           
self.block.all_x = Set(initialize=range(1, self.n_nodes + 1), ordered=True)
Then I've defined the variables as:

self.block.temperature_out_cv = Var(lines, self.block.all_time, self.block.all_x)


And finally, we have the calculation of the temperatures at different times:
            for j in self.block.all_x:
               
def _bc_temp_out(b, l, t):
                   
if mass_flow.all() == 0:
                       
return Constraint.Skip
                   
elif t == 0:
                       
return b.temperature_out_cv[l, t, j] == float(self.params['temperature_init_cv_' + l].v())
                   
else:
                       
for i in range(t+1):
                           
if i == 0:
                                b
.temperature_out_cv[l, i, j] = float(self.params['temperature_init_cv_' + l].v())
                           
else:
                               
if j == 1:
                                   
return b.temperature_out_cv[l, i, j] == (b.temperature_out_cv[l, i - 1, j] + b.u[
                                        i
] * time_step / self.params['delta_x'].v() * b.temperatures[l, i]
                                                                     
+ time_step / Z * Tg[i]) / (
                                                                           
1 + b.u[i] * time_step / self.params[
                                                                       
'delta_x'].v()
                                                                           
+ time_step / Z)
                               
else:
                                   
return b.temperature_out_cv[l, i, j] == (b.temperature_out_cv[l, i - 1, j] + b.u[
                                        i
] * time_step / self.params['delta_x'].v() * b.temperature_out_cv[
                                                                         l
, i, j - 1]
                                                                     
+ time_step / Z * Tg[i]) / (
                                                                           
1 + b.u[i] * time_step / self.params[
                                                                       
'delta_x'].v()
                                                                           
+ time_step / Z)

               
self.block.add_component('_bc_temp_out' + str(j), Constraint(lines, self.block.all_time, rule=_bc_temp_out))
but I get the error below:
ERROR: Rule failed when generating expression for constraint
 
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pyomo\core\base\constraint.py", line 779, in construct
    bbThor
._bc_temp_out1 with index ('supply', 1): AttributeError: 'Series'
    ndx
)
   
object has no attribute 'is_expression_type'
ERROR
: Constructing component 'bbThor._bc_temp_out1' from data=None failed:
 
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pyomo\core\base\misc.py", line 57, in apply_indexed_rule
   
return rule(model, *index)
 
File "C:\Users\Armaghan Bhr\Desktop\modesto-master\modesto\pipe.py", line 1723, in _bc_temp_out
   
AttributeError: 'Series' object has no attribute 'is_expression_type'
   
+ time_step / Z * Tg[i]) / (
 
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pyomo\core\expr\numvalue.py", line 772, in __add__
   
return _generate_sum_expression(_add,self,other)
 
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pyomo\core\expr\numeric_expr.py", line 1720, in _generate_sum_expression
   
if not (_other.__class__ in native_types or _other.is_expression_type()):
 
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pandas\core\generic.py", line 5179, in __getattr__
   
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'is_expression_type'
while time_step and Z are constant and Tg[i] is a pandas series. I've also printed these 3 parameters but still get the same error.





Armaghan Bhr

unread,
Apr 23, 2020, 2:08:01 PM4/23/20
to Pyomo Forum
I should mention that time_step and Z are constant and Tg[i] is a pandas series

Nicholson, Bethany L.

unread,
Apr 23, 2020, 3:34:05 PM4/23/20
to pyomo...@googlegroups.com

You can't use a Pandas Series object directly in a Pyomo expression. You have to extract the desired constant value from the Series.


Bethany


From: pyomo...@googlegroups.com <pyomo...@googlegroups.com> on behalf of Armaghan Bhr <armaghan...@gmail.com>
Sent: Thursday, April 23, 2020 10:50 AM
To: Pyomo Forum
Subject: [EXTERNAL] AttributeError: 'Series' object has no attribute 'is_expression_type'
 
--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/5e27a908-106a-4a89-95a9-999338e0700f%40googlegroups.com.

Armaghan Bhr

unread,
Apr 23, 2020, 3:40:02 PM4/23/20
to pyomo...@googlegroups.com
Thanks for your reply!
but that's what I did. Here the Tg parameter is defined:
    def create_params(self):
       params = Component.create_params(self)
       params.update({
           'diameter': DesignParameter('diameter',
                                       'Pipe diameter',
                                       'DN (mm)', mutable=True),
           'Tg': WeatherDataParameter('Tg',
                                      'Undisturbed ground temperature',
                                      'K')})

Then I extract the constant value from series:
Tg = self.params['Tg'].v() # ground temperature (T_out in equation 4)
Also in order to set up the main model, we have:
time_index = pd.DatetimeIndex(start=start_time, freq=str(time_step) + 'S', periods=n_steps)
# Ground temperature
t_g = pd.Series(12 + 273.15, index=t_amb.index)



To unsubscribe from this group and stop receiving emails from it, send an email to pyomo...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages