Passing Tensors to package which accept jumpy array

Hi everyone,
I am using pymc3 to sample temperature from a distribution and getting some thermodynamic properties from cantera https://cantera.org.

The syntax is passing the temperature, pressure and mass fractions to the gas object

gas.TPY=temperature, pressure, mass_fraction.

Afterwards, the object gas can be called to access all the thermodynamic variables such as density rho=gas.density.

However, cantera complains that temperature is a tensor variable (and not numpy scalar).

Is there any hope I can still use these packages together.

Thanks,
-M

Try wrapping the related function you call in cantera with theano.as_op, a quick start see https://docs.pymc.io/notebooks/getting_started.html?highlight=theano%20ops#Arbitrary-deterministics

@junpenglao thank you.

I will assume your response is the solution. However, changing the cantera package will be nightmare for me. Anyway, thanks a lot.

Depending on how cantera is called inside your pymc3 model. If it is a class that you want to input pymc3 random variable and then use some class method to compute simulation, maybe you can try wrapping everything into a theano.as_op:

@theano.as_op([...])
def fun(*args, **kwargs):
    cls = cantera.cls(*args, **kwargs)
    return cls.method(...)

Thank you. The solution is working now.

1 Like