Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing of Sum with step=2 does not work #70

Open
goerz opened this issue May 22, 2018 · 0 comments
Open

Printing of Sum with step=2 does not work #70

goerz opened this issue May 22, 2018 · 0 comments
Labels
printing enhancements to the printing system
Milestone

Comments

@goerz
Copy link
Member

goerz commented May 22, 2018

The printers currently cannot handle sums whose index goes over a range with a step other than 1:

>>> from qnet import *
>>> i = IdxSym('i'); j = IdxSym('j')
>>> ket_i = BasisKet(FockIndex(i), hs=0)
>>> s = Sum(i, 1, 10, step=2)(ket_i)
>>> srepr(s)
"KetIndexedSum(BasisKet(FockIndex(IdxSym('i', integer=True)), hs=LocalSpace('0')), IndexOverRange(IdxSym('i', integer=True), 1, 10, step=2))"
>>> ascii(s)
Traceback (most recent call last):
  File "<ipython-input-8-f3c3ef6dce87>", line 1, in <module>
    ascii(s)
  File "/Users/goerz/Documents/Programming/github/QNET/src/qnet/printing/__init__.py", line 319, in ascii
    return ascii.printer.doprint(expr)
  File "/Users/goerz/Documents/Programming/github/QNET/src/qnet/printing/base.py", line 196, in doprint
    res = self._str(self._print(expr, *args, **kwargs))
  File "/Users/goerz/Documents/Programming/github/QNET/.venv/py36/lib/python3.6/site-packages/sympy/printing/printer.py", line 257, in _print
    return getattr(self, printmethod)(expr, *args, **kwargs)
  File "/Users/goerz/Documents/Programming/github/QNET/src/qnet/printing/asciiprinter.py", line 486, in _print_IndexedSum
    current_index = self.doprint(index_range, which='bottom_index')
  File "/Users/goerz/Documents/Programming/github/QNET/src/qnet/printing/base.py", line 196, in doprint
    res = self._str(self._print(expr, *args, **kwargs))
  File "/Users/goerz/Documents/Programming/github/QNET/.venv/py36/lib/python3.6/site-packages/sympy/printing/printer.py", line 257, in _print
    return getattr(self, printmethod)(expr, *args, **kwargs)
  File "/Users/goerz/Documents/Programming/github/QNET/src/qnet/printing/asciiprinter.py", line 565, in _print_IndexOverRange
    bottom_rhs += ", %s" % expr.start_from + expr.step
TypeError: must be str, not int

One this is fixed, the doctest of Sum can be updated to test this case.

@goerz goerz added the printing enhancements to the printing system label May 22, 2018
@goerz goerz added this to the v2.0 milestone May 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
printing enhancements to the printing system
Projects
None yet
Development

No branches or pull requests

1 participant