Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
0 votes

The following two snippets of code are taken from the manual. They both now fail with AttributeError: 'cadabra2.ExNode' object has no attribute 'top'.

Am I doing something wrong?

This is using Cadabra2 2.4.5.2 Ubuntu 22.04

Snippet 1:

from cdb.core.component import *

{x, y, z}::Coordinate.
{i, j}::Indices(values={x, y, z}, position=fixed).
ex := a_{i}a_{j};
evaluate(ex, $a_{x} = k, a_{y} = l, a_{z} = m$)
substitute(ex, $k m -> 0$);
remove_zero_components(ex);

Snippet 2:

from cdb.core.component import *

{x, y, z}::Coordinate.
{i, j}::Indices(values={x, y, z}, position=fixed).
ex := b_{i j} = a_{i}a_{j};
evaluate(ex, $a_{x} = k, a_{y} = l, a_{z} = m$, rhsonly=True);
# substitute(ex, $k m -> 0$);
components_to_subrule(ex);
in Bug reports by (2.0k points)

I cannot reproduce that here, these both do what they are supposed to do for me. It may be because of some other things you did before running these snippets If you run one of these snippets in a fresh session, do they still produce an error?

Yes, I just created a new "untitled.ipynb" on my Jupyter notebook.

Could it be this is specific to Jupyter, ".ipynb" files, cdb 2.4.5.2 or Ubuntu 22.04?

The snippet I used is

from cdb.core.component import *

{x, y, z}::Coordinate.
{i, j}::Indices(values={x, y, z}, position=fixed).
ex := a_{i}a_{j};
evaluate(ex, $a_{x} = k, a_{y} = l, a_{z} = m$)
substitute(ex, $k m -> 0$);
remove_zero_components(ex);

and the full details of the error are

Traceback (most recent call last):
  File "/usr/lib/python3.10/dist-packages/cadabra2_jupyter/kernel.py", line 56, in do_execute
    self._execute_python(pycode)
  File "/usr/lib/python3.10/dist-packages/cadabra2_jupyter/kernel.py", line 110, in _execute_python
    self._sandbox_context(pycode)
  File "/usr/lib/python3.10/dist-packages/cadabra2_jupyter/context.py", line 51, in __call__
    exec(code, self._sandbox)
  File "<string>", line 8, in <module>
  File "/home/gpn/.config/cadabra_packages/cdb/core/component.py", line 66, in remove_zero_components
    if get_lhs(node).head() == r'\comma':
  File "/home/gpn/.config/cadabra_packages/cdb/core/manip.py", line 50, in get_lhs
    if n_args(ex.top()) != 2:
AttributeError: 'cadabra2.ExNode' object has no attribute 'top'

Many thanks

GPN

1 Answer

+2 votes
 
Best answer

You have a mixture of two installations, one in /usr/lib/python3.10/dist-packages/ and one (packages only) in /home/gpn/.config/cadabra_packages/.

I would remove (or temporarily move into a different location) the /home/gpn/.config/cadabra_packages/ folder and then try again.

by (80.3k points)
selected by

Yes, that worked. Thank you!

What did I do wrong, that caused my ".config" folder to get out of whack?

Thanks

GPN

I think we accidentally installed packages in ~/.config/ at some point in the past. So not your fault.

...