Re: [EXTERNAL] TypeError: unsupported operand type(s) for *: 'int' and 'function'

463 views
Skip to first unread message

Watson, Jean-Paul

unread,
Dec 10, 2016, 2:37:10 PM12/10/16
to pyomo...@googlegroups.com

This one is for Gabe and/or John. I went through your types and examples somewhat carefully, and don’t see anything weird at all.

 

jpw

 

From: <pyomo...@googlegroups.com> on behalf of acastillo <anya.c...@gmail.com>
Reply-To: "pyomo...@googlegroups.com" <pyomo...@googlegroups.com>
Date: Friday, December 9, 2016 at 4:12 PM
To: Pyomo Forum <pyomo...@googlegroups.com>
Subject: [EXTERNAL] TypeError: unsupported operand type(s) for *: 'int' and 'function'

 

I'm getting the following error:

 

>>> type(mp.Delta)

<class 'float'>

>>> type(mp.e[omega,t,s])

<class 'pyomo.core.base.var._GeneralVarData'>

>>> type(mp.p_c[omega,t,s])

<class 'pyomo.core.base.var._GeneralVarData'>

>>> type(mp.E_0[s])

<class 'float'>

>>> type(mp.Mu[s])

<class 'float'>

>>> type(mp.Eta_d[s])

<class 'float'>

>>> type(mp.p_d[omega,t,s])

<class 'pyomo.core.base.var._GeneralVarData'>

>>> type(mp.p_c[omega,t,s])

<class 'pyomo.core.base.var._GeneralVarData'>

>>> type(mp.Eta_c[s])

<class 'float'>

>>> mp.e[omega,t,s] == mp.Delta*(mp.Eta_c[s]*mp.p_c[omega,t,s]-mp.p_d[omega,t,s]/mp.Eta_d[s])+mp.Mu[s]*mp.E_0[s]  

<pyomo.core.base.expr_coopr3._EqualityExpression object at 0x1119db7c8>

>>> mp.e[omega,t,s] == mp.Mu[s]*mp.E_0[s]+mp.Delta*(mp.Eta_c[s]*mp.p_c[omega,t,s]-mp.p_d[omega,t,s]/mp.Eta_d[s])  

Traceback (most recent call last):

  File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev_5.0.0.201605051159/pysrc/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec

    exec(exp, global_vars, local_vars)

  File "<console>", line 1, in <module>

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/numvalue.py", line 466, in __radd__

    return generate_expression(_radd,self,other)

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/expr_coopr3.py", line 1105, in generate_expression

    ans._coef = [ multiplier * other._coef ]

TypeError: unsupported operand type(s) for *: 'int' and 'function'

 

Both of the last lines (above) are the same, just re-arranged expression terms 1 & 2. However, I still get the following error once the constraint is built:

ERROR:pyomo.core:Constructing component 'storage_resource_constraints.energy_storage_level' from data=None failed:

TypeError: unsupported operand type(s) for *=: 'function' and 'int'

Traceback (most recent call last):

  File "/Users/arcasti/Documents/workspace/offer_engine/scheduler/model.py", line 80, in <module>

    main()

  File "/Users/arcasti/Documents/workspace/offer_engine/scheduler/model.py", line 73, in main

    model = create_scheduler_offer_model()

  File "/Users/arcasti/Documents/workspace/offer_engine/scheduler/model.py", line 64, in create_scheduler_offer_model

    storage_resource_constraints(model) # constraints (8)-(17)

  File "/Users/arcasti/Documents/workspace/offer_engine/scheduler/block.py", line 27, in storage_resource_constraints

    eq_energy_storage_level(b) # constraint (8)

  File "/Users/arcasti/Documents/workspace/offer_engine/scheduler/con.py", line 55, in eq_energy_storage_level

    m.energy_storage_level = Constraint(mp.scenario_set,mp.time_interval,mp.storage_set,rule=_eq_energy_storage_level)

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/block.py", line 483, in __setattr__

    self.add_component(name, val)

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/block.py", line 849, in add_component

    val.construct(data)

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/constraint.py", line 749, in construct

    cdata = self._check_skip_add(ndx, tmp)

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/constraint.py", line 897, in _check_skip_add

    condata.set_value(expr)

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/constraint.py", line 473, in set_value

    _args[1])

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/expr_coopr3.py", line 910, in generate_expression_bypassCloneCheck

    ans = generate_expression(etype, _self, other)

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/expr_coopr3.py", line 1057, in generate_expression

    other.negate()

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/expr_coopr3.py", line 743, in negate

    self.scale(-1)

  File "/Users/arcasti/python34/pyomo/src/pyomo/pyomo/core/base/expr_coopr3.py", line 739, in scale

    self._coef[i] *= val

TypeError: unsupported operand type(s) for *=: 'function' and 'int'

 

The original code is as follows:

def eq_energy_storage_level(m): # constraint (8)

    mp = m.parent_block()

    t_0 = min(mp.time_interval)

    def _eq_energy_storage_level(_m,omega,t,s):

        if t > t_0:

            return mp.e[omega,t,s] == mp.Mu[s]*mp.e[omega,t-1,s] + mp.Delta*(mp.Eta_c[s]*mp.p_c[omega,t,s]-mp.p_d[omega,t,s]/mp.Eta_d[s])  

        else:

            return mp.e[omega,t,s] == mp.Mu[s]*mp.E_0[s] + mp.Delta*(mp.Eta_c[s]*mp.p_c[omega,t,s]-mp.p_d[omega,t,s]/mp.Eta_d[s])               

    m.energy_storage_level = Constraint(mp.scenario_set,mp.time_interval,mp.storage_set,rule=_eq_energy_storage_level)

 

Advice?? Thanks! -Anya

--
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.
For more options, visit https://groups.google.com/d/optout.

Siirola, John D

unread,
Dec 10, 2016, 2:43:54 PM12/10/16
to pyomo...@googlegroups.com

Anya,

 

Can you send me the model + data off-list so that I can look at it?

 

Thanks,

john

Reply all
Reply to author
Forward
0 new messages