Improvements to the 'Structures in Coding Theory' thematic tutorial

55 views
Skip to first unread message

marki...@gmail.com

unread,
Apr 23, 2017, 6:51:02 AM4/23/17
to sage-devel
Hi all,


I recently worked through the coding theory thematic tutorial "structures in coding theory" which teaches users how to create custom code classes. The tutorial in question is available from:

https://doc.sagemath.org/html/en/thematic_tutorials/structures_in_coding_theory.html


I noticed two problems which I've come up with solutions for, but I would like to check that I haven't done something silly (as I am new to Sage). For the record, I am running Sage version 8.0.beta2, Release Date: 2017-04-12 on 64-bit Ubuntu Linux 16.04. They problems are small but since the tutorial is aimed at people who may be learning to dig around in the source code for the first time, I think they are worth looking at. Please let me know if I should open a ticket and fix the following problems.


Many thanks,
Mark.


Problem 1
The constructor for the repetition code in repetition_code.py uses GF(2). In order to avoid Error 1 (below) I needed to add the following line to reptition_code.py:
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF

Error 1
sage: codes.BinaryRepetitionCode(3)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-43e4a5a8cb42> in <module>()
----> 1 codes.BinaryRepetitionCode(Integer(3))

/home/mark/git/sage/local/lib/python2.7/site-packages/sage/coding/repetition_code.pyc in __init__(self, length)
     13
     14     def __init__(self, length):
---> 15         super(BinaryRepetitionCode, self).__init__(GF(2), length, "RepetitionGeneratorMatrixEncoder", "MajorityVoteDecoder")
     16         self._dimension = 1
     17

NameError: global name 'GF' is not defined


Problem 2

As described in section VI of the tutorial, once the user has written their repetition_code.py file they need to add some lines to codes_catalog.py, encoders_catalog.py and decoders_catalog.py. If the user follows the tutorial exactly and adds, for example,


   from repetition_code import BinaryRepetitionCode


to codes_catalog.py then they will generally encounter Error 2 (below). Note that if the user runs ../../../sage -br from sage/src/sage/coding then they will not encounter Error 2. In order to avoid Error 2 they could instead be instructed to add


   from sage.coding.repetition_code import BinaryRepetitionCode

to codes_catalog.py (and similar for the other files in question).

Error 2

sage: codes.HammingCode(GF(2),3)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-2617e5c84fa6> in <module>()
----> 1 codes.HammingCode(GF(Integer(2)),Integer(3))

/home/mark/git/sage/src/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__getattr__ (/home/mark/git/sage/src/build/cythonized/sage/misc/lazy_import.c:3866)()
    355             True
    356         """
--> 357         return getattr(self._get_object(), attr)
    358
    359     # We need to wrap all the slot methods, as they are not forwarded

/home/mark/git/sage/src/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport._get_object (/home/mark/git/sage/src/build/cythonized/sage/misc/lazy_import.c:2507)()
    247         elif self._at_startup and not startup_guard:
    248             print('Option ``at_startup=True`` for lazy import {0} not needed anymore'.format(self._name))
--> 249         self._object = getattr(__import__(self._module, {}, {}, [self._name]), self._name)
    250         alias = self._as_name or self._name
    251         if self._deprecation is not None:

/home/mark/git/sage/local/lib/python2.7/site-packages/sage/coding/codes_catalog.py in <module>()
     34 from sage.coding.linear_code import LinearCode
     35 #from sage.coding.repetition_code import BinaryRepetitionCode
---> 36 from repetition_code import BinaryRepetitionCode
     37
     38 _lazy_import('sage.coding.code_constructions',

ImportError: No module named repetition_code


Simon King

unread,
Apr 23, 2017, 10:39:24 AM4/23/17
to sage-...@googlegroups.com
Hi Mark,

On 2017-04-23, marki...@gmail.com <marki...@gmail.com> wrote:
> ...
> https://doc.sagemath.org/html/en/thematic_tutorials/structures_in_coding_theory.html
>
> *Problem 1*
> The constructor for the repetition code in repetition_code.py uses GF(2).
> In order to avoid Error 1 (below) I needed to add the following line to
> reptition_code.py:
> from sage.rings.finite_rings.finite_field_constructor import FiniteField as
> GF

Most of the tutorials and doc tests are written in terms of interactive code,
i.e., code that works on the SageMath command line (or notebook). In an
interactive session, GF and many other things do not need to be imported.
However, if one creates a Python module using Sage, everything of course
needs to be imported, and also Sage's syntax such as "2^5" instead of
"2**5" won't work.

However, the tutorial you are mentioning explicitly is about writing
files "repetition_code.py" etc, and they do *not* advise to import
what is needed. I agree with you that they should.

Best regards,
Simon

David Lucas

unread,
Apr 24, 2017, 8:02:31 AM4/24/17
to sage-devel
Hello,

I completely overlooked that when I wrote this tutorial...


They problems are small but since the tutorial is aimed at people who may be learning to dig around in the source code for the first time, I think they are worth looking at. Please let me know if I should open a ticket and fix the following problems.

I do agree with Simon and you, this should be fixed. You can of course open a ticket for this!
Cc me on your trac ticket (my ID is dlucas) and I will review your changes.

Glad to hear that some people are using this tutorial.
If you find any other issues, please let me know :)

Best,

David

 

marki...@gmail.com

unread,
Apr 24, 2017, 8:27:48 AM4/24/17
to sage-devel

I do agree with Simon and you, this should be fixed. You can of course open a ticket for this!
Cc me on your trac ticket (my ID is dlucas) and I will review your changes.

Great! I've made the necessary changes. Once I get my trac account set up properly I'll submit them.

Thank you both for your advice.

Mark.
Reply all
Reply to author
Forward
0 new messages