IPython notebooks example not working

+1 vote

Hi,

I am trying to use Cadabra2 in IPython Notebooks. However, I get errors when I try to copy commands from the "Cadabra inside IPython/Jupyter" tutorial. For example, the following code

from cadabra2 import *
from IPython.display import display, Math, Latex

ex=Ex(r"A_{m n}")
Symmetric(ex)


gives the following error:
__init__(): incompatible constructor arguments. The following argument types are supported: 1. cadabra2.Symmetric(ex: cadabra2.Ex, param: cadabra2.Ex)

The samme happens if I try to initialize indices. It seems the functions giving error expects two arguments rather than one. Am I doing something wrong?

The param argument should have been optional, but at some point we stripped out the default value for that argument, and since the Cadabra preparser fills it in automatically, no-one noticed.

Until this is fixed, you can use

Symmetric(ex, Ex(''))


in place of your last line (that is, set param equal to an empty expression).

Great, thank you!

May I ask what is the correct way to specify optional arguments? The following does not seem to be correct

Indices(Ex(r"{m,n,p,q,r,s,t}"), Ex('fixed'))


I apologize if this is available in the documentation somewhere.

The documentation on how to use Cadabra directly from Python is very minimal, so please do ask if you get stuck (or, alternatively, switch to using the Cadabra notebook; life is much easier there).

Indices(Ex(r"{m,n,p,q,r,s,t}"), Ex(r"position=fixed"))


Note that if you have previously (in the same session) declared this index set in a different way, the type info will not get overwritten.

Thanks again. I will give IPython a shot, but if it is too much trouble I will consider switching to Cadabra notebook.

In principle, if someone would volunteer to write an IPython/Jupyter kernel for Cadabra, this could all be much nicer there too ;-)

+1 vote

My old answer is no longer relevant; the current version (2.3.0 onwards) handles your example just fine.