Ticket #7921 (closed enhancement: fixed)

Opened 8 months ago

Last modified 8 months ago

Categories for extension types via __getattr___

Reported by: nthiery Owned by: nthiery
Priority: major Milestone: sage-4.3.2
Component: categories Keywords:
Cc: sage-combinat, mhansen, robertwb, roed Author(s): Nicolas M. Thiéry
Report Upstream: N/A Reviewer(s): Robert Bradshaw
Merged in: sage-4.3.2.alpha0 Work issues:

Description (last modified by nthiery) (diff)

With this patch, all parents and elements can inherit code from categories, even extension types. This includes in particular generic tests (see TestSuite?(...).run()):

sage: ZZ.category()
Category of commutative rings
sage: TestSuite(ZZ).run(verbose = True)
running ._test_additive_associativity() . . . pass
running ._test_an_element() . . . pass
running ._test_associativity() . . . pass
running ._test_element_pickling() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_one() . . . pass
running ._test_pickling() . . . pass
running ._test_prod() . . . pass
running ._test_some_elements() . . . pass
running ._test_zero() . . . pass

It is to be expected that this will catch bugs in many places in the library. To start with, see #7922, #7929, #7945, #7946

See patch description for details.

Patch also available on the sage-combinat server, with a +category guard:  http://combinat.sagemath.org/hgwebdir.cgi/patches/file/tip/trac_7921-categories_for_extension_types-nt.patch

Attachments

categories_testsuite-nt.patch Download (64.2 KB) - added by nthiery 8 months ago.
Patch 2: stronger category tests
trac_7921-categories_for_extension_types-nt.patch Download (82.7 KB) - added by nthiery 8 months ago.
Rebased and updated one doctest for 4.3.1 + micro fix in the primer. Apply only this one.

Change History

  Changed 8 months ago by nthiery

  • cc roed added; roe removed
  • description modified (diff)

  Changed 8 months ago by nthiery

  • status changed from new to needs_work
  • description modified (diff)

All tests seem to pass with it on 4.3; I still need to double check a couple things. It does change things in many places; so the best would be to integrate it in the early phase of 4.3.2 before it rots away.

Early feedback welcome!

  Changed 8 months ago by nthiery

  • status changed from needs_work to needs_review
  • description modified (diff)

  Changed 8 months ago by nthiery

  • description modified (diff)

The patch passes all tests with sage 4.3 + sage-combinat patches merged in 4.3.1 on my machine. I'll run sage -t -long tonight and report.

  Changed 8 months ago by nthiery

  • reviewer set to Robert Bradshaw
  • description modified (diff)

Hi Robert; I improved a bit TestSuite? to catch more. Should I add a second patch to this one, or make it a separate ticket?

  Changed 8 months ago by nthiery

Robert: please let me know if I should open a separate ticket for the second patch. Florent can probably review it if this can save you some time.

Changed 8 months ago by nthiery

Patch 2: stronger category tests

follow-up: ↓ 10   Changed 8 months ago by robertwb

  • status changed from needs_review to needs_info

The attribute lookup code looks good. Most of the other changes are minor, though changing loads/dumps to running tests is an independent change is seems.

sage/groups/group.pyx

    def __call__(self, x): # NT: doesn't this get in the way of the coercion mechanism? 

Groups are not yet converted over to the new coercion model, and are a mess in general.

In sage/modular/abvar/abvar.py, you removed the method but kept the docstring floating there. Those tests should be kept, but probably not put there.

sage/modules/free_module.py - It'd be good to test the category of non-vector space.

Could you explain the changes to sage/structure/sage_object.pyx?

follow-up: ↓ 9   Changed 8 months ago by robertwb

I didn't look much at the second patch, but this should almost certainly be a second ticket.

in reply to: ↑ 8 ; follow-up: ↓ 11   Changed 8 months ago by nthiery

  • status changed from needs_info to needs_review

Replying to robertwb:

I didn't look much at the second patch, but this should almost certainly be a second ticket.

Ok, will do. Florent volunteered to review it, since it's mostly about testsuites and categories.

in reply to: ↑ 7 ; follow-up: ↓ 12   Changed 8 months ago by nthiery

  • milestone set to sage-4.3.2

Replying to robertwb:

The attribute lookup code looks good. Most of the other changes are minor, though changing loads/dumps to running tests is an independent change is seems.

Well, I actually only added 2/3 of them, mostly as an attempt to catch possible introduced issues. The others were already there, and needed to be updated due to all the new (often failing) tests coming from categories.

sage/groups/group.pyx {{{ def call(self, x): # NT: doesn't this get in the way of the coercion mechanism? }}} Groups are not yet converted over to the new coercion model, and are a mess in general.

Ok. Shouldn't this def be removed, so as not to prevent groups inheriting from Group to progressively get converted to the coercion model? Sure, that should be a separate patch. As for the comment above: I just can't prevent myself from adding comments in the code when I stumble on strange stuff. I can remove it if you prefer.

In sage/modular/abvar/abvar.py, you removed the method but kept the docstring floating there. Those tests should be kept, but probably not put there.

Oops, fixed.

sage/modules/free_module.py - It'd be good to test the category of non-vector space.

Done.

Could you explain the changes to sage/structure/sage_object.pyx?

I improved the description on top of the patch, including a comment about this.

in reply to: ↑ 9   Changed 8 months ago by nthiery

Replying to nthiery:

Replying to robertwb:

I didn't look much at the second patch, but this should almost certainly be a second ticket.

Ok, will do. Florent volunteered to review it, since it's mostly about testsuites and categories.

This is now #8001 (darn, missed, that was sooo close from #8000!)

in reply to: ↑ 10 ; follow-up: ↓ 13   Changed 8 months ago by robertwb

  • status changed from needs_review to positive_review

Replying to nthiery:

Replying to robertwb:

The attribute lookup code looks good. Most of the other changes are minor, though changing loads/dumps to running tests is an independent change is seems.

Well, I actually only added 2/3 of them, mostly as an attempt to catch possible introduced issues. The others were already there, and needed to be updated due to all the new (often failing) tests coming from categories.

OK.

sage/groups/group.pyx {{{ def call(self, x): # NT: doesn't this get in the way of the coercion mechanism? }}} Groups are not yet converted over to the new coercion model, and are a mess in general.

Ok. Shouldn't this def be removed, so as not to prevent groups inheriting from Group to progressively get converted to the coercion model?

Eventually, for sure.

Sure, that should be a separate patch. As for the comment above: I just can't prevent myself from adding comments in the code when I stumble on strange stuff. I can remove it if you prefer.

No, comments like this are good. I was just somewhat answering your question.

Could you explain the changes to sage/structure/sage_object.pyx?

I improved the description on top of the patch, including a comment about this.

Thanks. Look forward to being able to do stuff like this. On a somewhat related note, you might be interested in the binop decorator at #383.

in reply to: ↑ 12   Changed 8 months ago by nthiery

Thanks Robert for the quick review! I am looking forward feedback from practical uses :-)

Thanks also for the pointer to #383

Changed 8 months ago by nthiery

Rebased and updated one doctest for 4.3.1 + micro fix in the primer. Apply only this one.

  Changed 8 months ago by mvngu

  • status changed from positive_review to closed
  • resolution set to fixed
  • merged set to sage-4.3.2.alpha0
Note: See TracTickets for help on using tickets.