Your upindex
object is a string. In order to pull a symbol with a python name into a Cadabra maths expression with the @(...)
operator, it needs to be a Cadabra Ex
object. So convert your upindex
to an Ex
and it should work: instead of
upindex = random.choice(indeces)
use
upindex = Ex( random.choice(indeces) )