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

Add Oriented Matroids Package #38024

Open
wants to merge 51 commits into
base: develop
Choose a base branch
from

Conversation

thecaligarmo
Copy link
Contributor

This pull request merges the Oriented Matroids package that I developed (see https://github.com/thecaligarmo/oriented_matroids) into Sage so that others may develop directly into it rather than relying solely on myself.

This package should resolve ticket #18703 and in addition, my package should be removed from #31164 as this pull request will put Oriented Matroids directly into Sage rather than requiring a package.

If there are any changes needing to be made, just let me know and we can go from there.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@thecaligarmo
Copy link
Contributor Author

The Build & Test action seems to be failing, but I can't figure out why. It's stating it's not a git repository, when it clearly is. Not sure how to fix it.

Copy link

github-actions bot commented May 18, 2024

Documentation preview for this PR (built with commit 46c149c; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@gmou3
Copy link
Contributor

gmou3 commented May 19, 2024

The Build & Test action seems to be failing, but I can't figure out why. It's stating it's not a git repository, when it clearly is. Not sure how to fix it.

Don't worry about that, it is some error of the tester.

src/sage/matroids/all.py Outdated Show resolved Hide resolved
"""
if hasattr(self, "_circuits"):
return self._circuits
raise NotImplementedError("Circuits not implemented")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend all Error messages to start uncapitalized and end without a dot.

\mathcal{C} / A = \left\{ X\mid_{E \backslash A} : X \in \mathcal{C} \text{ and} A \subseteq X^0 \right\}

"""
# sage: from sage.matroids.oriented_matroids.oriented_matroid import OrientedMatroid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do something with this commented code?


AUTHORS:

- Aram Dermenjian (): initial version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add date or complete/delete file.

@thecaligarmo
Copy link
Contributor Author

@gmou3 I've gone ahead and fixed the things you wanted.

@gmou3
Copy link
Contributor

gmou3 commented Jul 4, 2024

Thanks. I had opened a PR a while ago with some formatting recommendations. Please have a look and merge or close it please.

@thecaligarmo
Copy link
Contributor Author

I hadn't noticed the pull request for some reason. I've added your changes as well and double checked things work nicely. Thanks for that.

@thecaligarmo
Copy link
Contributor Author

Ok, I've gone ahead and altered the code to use a class instead of a constructor. We'll make a different PR for doing the same to Matroids (Which I believe should be done as well)

@gmou3
Copy link
Contributor

gmou3 commented Oct 6, 2024

I can implement the corresponding changes for Matroid after the present PR is finalized and merged.
So feel free to diverge if it produces some improvement.

@gmou3
Copy link
Contributor

gmou3 commented Oct 28, 2024

Have the desired changes been implemented according to @tscrim?

@thecaligarmo
Copy link
Contributor Author

Have the desired changes been implemented according to @tscrim?

Yes. I think all the changes desired by @tscrim have been implemented. Unless I missed something or if there are new ones?

Copy link
Contributor

@gmou3 gmou3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then, it also looks good to me.

Let's leave further work for future PRs.

Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many things that need to be done before this can be included. Some of them are very important (all methods need doctests, even hidden and abstract ones); some of them are more minor (doc formatting I saw from checking the compiled doc); some are not necessary but trying to make the code within Sage more uniform.

Comment on lines +405 to +408
"""
Return the dual oriented matroid.
EXAMPLES::
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""
Return the dual oriented matroid.
EXAMPLES::
"""
Return the dual oriented matroid.
EXAMPLES::

You should add an example for the case when there is no dual. If no such case exists, then this should be an @abstract_method (perhaps with optional=True).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that dual is not actually implemented yet. I had missed that an (incorrect) doctest was written by one of my mentees. I'll go ahead and fix this and see about adding code for making a dual.

r"""
Return the underlying matroid.
"""
pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pass

Abstract methods also still need a doctest (from one of the concrete implementations).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we're removing pass here? I guess I'm not understanding when it should be used if it's not used in these circumstances?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring actually does the same job as pass, but by not having it, it suggests there is no implementation (rather than pass which would simply do nothing).

src/sage/matroids/oriented_matroids/oriented_matroid.py Outdated Show resolved Hide resolved
src/sage/matroids/oriented_matroids/oriented_matroid.py Outdated Show resolved Hide resolved
vbraun pushed a commit to vbraun/sage that referenced this pull request Nov 2, 2024
    
When certificate is set to `True`, the method `is_valid` returns a tuple
of a boolean and a dictionary.
The dictionary provides some more information in case the matroid is not
valid.

Examples:
```
sage: M = matroids.catalog.Fano()
sage: M.is_valid()
True
sage: M.is_valid(certificate=True)
(True, {})

sage: C = [[1, 2, 3], [3, 4, 5]]
sage: M = Matroid(circuits=C)
sage: M.is_valid()
False
sage: M.is_valid(certificate=True)
(False,
 {'circuit 1': frozenset({3, 4, 5}),
  'circuit 2': frozenset({1, 2, 3}),
  'element': 3,
  'error': 'elimination axiom failed'})
```

To be done constistently with sagemath#38024.
    
URL: sagemath#38711
Reported by: gmou3
Reviewer(s): Travis Scrimshaw
Co-authored-by: Travis Scrimshaw <[email protected]>
@thecaligarmo
Copy link
Contributor Author

thecaligarmo commented Nov 9, 2024

@tscrim I'm trying to do TestSuite(E).run() on a SignedSubsetElement, but it keeps failing. From what I can tell, it's because of the following:

sage: from sage.matroids.oriented_matroids.oriented_matroid import OrientedMatroid
sage: from sage.matroids.oriented_matroids.signed_subset_element import SignedSubsetElement
sage: from sage.cpython.type import can_assign_class
sage: M = OrientedMatroid([[1],[-1]], key='circuit');
sage: E = SignedSubsetElement(M,data = (0,))
sage: can_assign_class(E)
True
sage: TestSuite(E).run()
Failure in _test_category:
Traceback (most recent call last):
  File "/sage/sagedev/src/sage/misc/sage_unittest.py", line 298, in run
    test_method(tester=tester)
  File "sage/structure/element.pyx", line 720, in sage.structure.element.Element._test_category
    tester.assertTrue(isinstance(self, self.parent().category().element_class))
  File "/usr/lib/python3.10/unittest/case.py", line 687, in assertTrue
    raise self.failureException(msg)
AssertionError: False is not true
------------------------------------------------------------
The following tests failed: _test_category

The isinstance(self, self.parent().category().element_class) line only runs if can_assign_class is true, but since that function is written in cython, I don't necessarily know what's happening to fix this. Do you know what this does or how to fix this?

To make life easier, here's the source for can_assign_class:

cpdef bint can_assign_class(obj) noexcept:
    """
    Can we assign ``obj.__class__``?

    Note that Python 3.5 has experimented with allowing assigning
    ``__class__`` in more cases but this was mostly reverted. In this
    function, we apply the Python 2.7 semantics.

    EXAMPLES::

        sage: class X: pass
        sage: from sage.cpython.type import can_assign_class
        sage: can_assign_class(X())
        True
        sage: class Y(int): pass
        sage: from sage.cpython.type import can_assign_class
        sage: can_assign_class(Y())
        True
        sage: can_assign_class(1)
        False
    """
    cdef PyTypeObject* tp = Py_TYPE(obj)
    if tp is PyInstance_Type:
        return True
    return (tp.tp_flags & Py_TPFLAGS_HEAPTYPE) != 0

@tscrim
Copy link
Collaborator

tscrim commented Nov 9, 2024

@tscrim I'm trying to do TestSuite(E).run() on a SignedSubsetElement, but it keeps failing.

It’s failing as it should because it doesn’t have a proper parent set. From what I can quickly see, it isn’t being used as an element in a set but a more generic helper object. So I would remove the inheritance from Element and instead derive from SageObject. It’s possible I missed something in its usage from a quick skim of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants