Unpickling methods - Matroid Theory

Skip to content
Back to top
View this page
Edit this page

# Unpickling methods

Python saves objects by providing a pair `(f, data)` such that `f(data)` reconstructs the object. This module collects the loading (_unpickling_ in Python terminology) functions for Sage’s matroids.

Note

The reason this code was separated out from the classes was to make it play nice with lazy importing of the `Matroid()` and `matroids` keywords.

AUTHORS:

- Rudi Pendavingh, Stefan van Zwam (2013-07-01): initial version

- Giorgos Mousa (2024-01-01): add CircuitsMatroid and FlatsMatroid

sage.matroids.unpickling.unpickle_basis_matroid(version, data)

  Unpickle a BasisMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer; expected to be 0

  - `data` – tuple `(E, R, name, BB)` in which `E` is the groundset of the matroid, `R` is the rank, `name` is a custom name, and `BB` is the bitpacked list of bases, as pickled by Sage’s `bitset_pickle`.

  OUTPUT: matroid

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.advanced import *
      sage: M = BasisMatroid(matroids.catalog.Vamos())
      sage: M == loads(dumps(M))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> from sage.matroids.advanced import *
      >>> M = BasisMatroid(matroids.catalog.Vamos())
      >>> M == loads(dumps(M))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_binary_matrix(version, data)

  Reconstruct a `BinaryMatrix` object (internal Sage data structure).

  Warning

  Users should not call this method directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.lean_matrix import *
      sage: A = BinaryMatrix(2, 5)
      sage: A == loads(dumps(A))  # indirect doctest
      True
      sage: C = BinaryMatrix(2, 2, Matrix(GF(2), [[1, 1], [0, 1]]))
      sage: C == loads(dumps(C))
      True

  Python

      >>> from sage.all import *
      >>> from sage.matroids.lean_matrix import *
      >>> A = BinaryMatrix(Integer(2), Integer(5))
      >>> A == loads(dumps(A))  # indirect doctest
      True
      >>> C = BinaryMatrix(Integer(2), Integer(2), Matrix(GF(Integer(2)), [[Integer(1), Integer(1)], [Integer(0), Integer(1)]]))
      >>> C == loads(dumps(C))
      True

sage.matroids.unpickling.unpickle_binary_matroid(version, data)

  Unpickle a BinaryMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer (currently 0)

  - `data` – tuple `(A, E, B, name)` where `A` is the representation matrix, `E` is the groundset of the matroid, `B` is the currently displayed basis, and `name` is a custom name.

    OUTPUT: `BinaryMatroid`

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1], [0, 1, 0, 1],
      ....:                            [0, 0, 1, 1]]))
      sage: M == loads(dumps(M))  # indirect doctest
      True
      sage: M.rename('U34')
      sage: loads(dumps(M))
      U34

  Python

      >>> from sage.all import *
      >>> M = Matroid(Matrix(GF(Integer(2)), [[Integer(1), Integer(0), Integer(0), Integer(1)], [Integer(0), Integer(1), Integer(0), Integer(1)],
      ...                            [Integer(0), Integer(0), Integer(1), Integer(1)]]))
      >>> M == loads(dumps(M))  # indirect doctest
      True
      >>> M.rename('U34')
      >>> loads(dumps(M))
      U34

sage.matroids.unpickling.unpickle_circuit_closures_matroid(version, data)

  Unpickle a CircuitClosuresMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer; expected to be 0

  - `data` – tuple `(E, CC, name)` in which `E` is the groundset of the matroid, `CC` is the dictionary of circuit closures, and `name` is a custom name.

  OUTPUT: matroid

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: M = matroids.catalog.Vamos()
      sage: M == loads(dumps(M))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> M = matroids.catalog.Vamos()
      >>> M == loads(dumps(M))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_circuits_matroid(version, data)

  Unpickle a CircuitsMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer; expected to be 0

  - `data` – tuple `(E, C, name)` in which `E` is the groundset of the matroid, `C` is the list of circuits , and `name` is a custom name.

  OUTPUT: matroid

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: M = matroids.Theta(5)
      sage: M == loads(dumps(M))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> M = matroids.Theta(Integer(5))
      >>> M == loads(dumps(M))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_dual_matroid(version, data)

  Unpickle a DualMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer; expected to be 0

  - `data` – tuple `(M, name)` in which `M` is the internal matroid, and `name` is a custom name

  OUTPUT: matroid

  Warning

  Users should not call this function directly. Instead, use load/save.

  EXAMPLES:

  Sage

      sage: M = matroids.catalog.Vamos().dual()
      sage: M == loads(dumps(M))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> M = matroids.catalog.Vamos().dual()
      >>> M == loads(dumps(M))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_flats_matroid(version, data)

  Unpickle a `FlatsMatroid`.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer; expected to be 0

  - `data` – tuple `(E, F, name)` in which `E` is the groundset of the matroid, `F` is the dictionary of flats, and `name` is a custom name.

  OUTPUT: matroid

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.flats_matroid import FlatsMatroid
      sage: M = FlatsMatroid(matroids.catalog.Vamos())
      sage: M == loads(dumps(M))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> from sage.matroids.flats_matroid import FlatsMatroid
      >>> M = FlatsMatroid(matroids.catalog.Vamos())
      >>> M == loads(dumps(M))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_gammoid(version, data)

  Unpickle a `Gammoid`.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer; expected to be 0

  - `data` – tuple `(D, roots, E, name)` in which `D` is a loopless DiGraph representing the gammoid, `roots` is a subset of the vertices, `E` is the groundset of the matroid, and `name` is a custom name.

  OUTPUT: matroid

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.gammoid import Gammoid
      sage: M = Gammoid(digraphs.TransitiveTournament(5), roots=[3, 4])
      sage: M == loads(dumps(M))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> from sage.matroids.gammoid import Gammoid
      >>> M = Gammoid(digraphs.TransitiveTournament(Integer(5)), roots=[Integer(3), Integer(4)])
      >>> M == loads(dumps(M))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_generic_matrix(version, data)

  Reconstruct a `GenericMatrix` object (internal Sage data structure).

  Warning

  Users should not call this method directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.lean_matrix import *
      sage: A = GenericMatrix(2, 5, ring=QQ)
      sage: A == loads(dumps(A))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> from sage.matroids.lean_matrix import *
      >>> A = GenericMatrix(Integer(2), Integer(5), ring=QQ)
      >>> A == loads(dumps(A))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_graphic_matroid(version, data)

  Unpickle a GraphicMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer (currently 0)

  - `data` – tuple consisting of a SageMath graph and a name

  OUTPUT: `GraphicMatroid`

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: M = Matroid(graphs.DiamondGraph())                                        # needs sage.graphs
      sage: M == loads(dumps(M))                                                      # needs sage.graphs
      True

  Python

      >>> from sage.all import *
      >>> M = Matroid(graphs.DiamondGraph())                                        # needs sage.graphs
      >>> M == loads(dumps(M))                                                      # needs sage.graphs
      True

sage.matroids.unpickling.unpickle_linear_matroid(version, data)

  Unpickle a LinearMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer (currently 0)

  - `data` – tuple `(A, E, reduced, name)` where `A` is the representation matrix, `E` is the groundset of the matroid, `reduced` is a boolean indicating whether `A` is a reduced matrix, and `name` is a custom name.

  OUTPUT: `LinearMatroid`

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2],
      ....:                                               [0, 1, 1, 1, 3]]))
      sage: M == loads(dumps(M))  # indirect doctest
      True
      sage: M.rename('U35')
      sage: loads(dumps(M))
      U35

  Python

      >>> from sage.all import *
      >>> M = Matroid(Matrix(GF(Integer(7)), [[Integer(1), Integer(0), Integer(0), Integer(1), Integer(1)], [Integer(0), Integer(1), Integer(0), Integer(1), Integer(2)],
      ...                                               [Integer(0), Integer(1), Integer(1), Integer(1), Integer(3)]]))
      >>> M == loads(dumps(M))  # indirect doctest
      True
      >>> M.rename('U35')
      >>> loads(dumps(M))
      U35

sage.matroids.unpickling.unpickle_minor_matroid(version, data)

  Unpickle a MinorMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer; currently \(0\)

  - `data` – tuple `(M, C, D, name)`, where `M` is the original matroid of which the output is a minor, `C` is the set of contractions, `D` is the set of deletions, and `name` is a custom name.

  OUTPUT: `MinorMatroid`

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: M = matroids.catalog.Vamos().minor('abc', 'g')
      sage: M == loads(dumps(M))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> M = matroids.catalog.Vamos().minor('abc', 'g')
      >>> M == loads(dumps(M))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_plus_minus_one_matrix(version, data)

  Reconstruct an `PlusMinusOneMatrix` object (internal Sage data structure).

  Warning

  Users should not call this method directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.lean_matrix import *
      sage: A = PlusMinusOneMatrix(2, 5)
      sage: A == loads(dumps(A))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> from sage.matroids.lean_matrix import *
      >>> A = PlusMinusOneMatrix(Integer(2), Integer(5))
      >>> A == loads(dumps(A))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_quaternary_matrix(version, data)

  Reconstruct a `QuaternaryMatrix` object (internal Sage data structure).

  Warning

  Users should not call this method directly.

  EXAMPLES:

  Sage

      sage: # needs sage.rings.finite_rings
      sage: from sage.matroids.lean_matrix import *
      sage: A = QuaternaryMatrix(2, 5, ring=GF(4, 'x'))
      sage: A == loads(dumps(A))  # indirect doctest
      True
      sage: C = QuaternaryMatrix(2, 2, Matrix(GF(4, 'x'), [[1, 1], [0, 1]]))
      sage: C == loads(dumps(C))
      True

  Python

      >>> from sage.all import *
      >>> # needs sage.rings.finite_rings
      >>> from sage.matroids.lean_matrix import *
      >>> A = QuaternaryMatrix(Integer(2), Integer(5), ring=GF(Integer(4), 'x'))
      >>> A == loads(dumps(A))  # indirect doctest
      True
      >>> C = QuaternaryMatrix(Integer(2), Integer(2), Matrix(GF(Integer(4), 'x'), [[Integer(1), Integer(1)], [Integer(0), Integer(1)]]))
      >>> C == loads(dumps(C))
      True

sage.matroids.unpickling.unpickle_quaternary_matroid(version, data)

  Unpickle a QuaternaryMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer (currently 0)

  - `data` – tuple `(A, E, B, name)` where `A` is the representation matrix, `E` is the groundset of the matroid, `B` is the currently displayed basis, and `name` is a custom name.

  OUTPUT: `TernaryMatroid`

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.advanced import *
      sage: M = QuaternaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1],
      ....:          [0, 0, 1, 1]]))
      sage: M == loads(dumps(M))  # indirect doctest
      True
      sage: M.rename('U34')
      sage: loads(dumps(M))
      U34
      sage: M = QuaternaryMatroid(Matrix(GF(4, 'x'), [[1, 0, 1],                      # needs sage.rings.finite_rings
      ....:                                           [1, 0, 1]]))
      sage: loads(dumps(M)).representation()                                          # needs sage.rings.finite_rings
      [1 0 1]
      [1 0 1]

  Python

      >>> from sage.all import *
      >>> from sage.matroids.advanced import *
      >>> M = QuaternaryMatroid(Matrix(GF(Integer(3)), [[Integer(1), Integer(0), Integer(0), Integer(1)], [Integer(0), Integer(1), Integer(0), Integer(1)],
      ...          [Integer(0), Integer(0), Integer(1), Integer(1)]]))
      >>> M == loads(dumps(M))  # indirect doctest
      True
      >>> M.rename('U34')
      >>> loads(dumps(M))
      U34
      >>> M = QuaternaryMatroid(Matrix(GF(Integer(4), 'x'), [[Integer(1), Integer(0), Integer(1)],                      # needs sage.rings.finite_rings
      ...                                           [Integer(1), Integer(0), Integer(1)]]))
      >>> loads(dumps(M)).representation()                                          # needs sage.rings.finite_rings
      [1 0 1]
      [1 0 1]

sage.matroids.unpickling.unpickle_rational_matrix(version, data)

  Reconstruct a `sage.matroids.lean_matrix.RationalMatrix` object (internal Sage data structure).

  Warning

  Users should not call this method directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.lean_matrix import RationalMatrix
      sage: A = RationalMatrix(2, 5)
      sage: A == loads(dumps(A))  # indirect doctest
      True

  Python

      >>> from sage.all import *
      >>> from sage.matroids.lean_matrix import RationalMatrix
      >>> A = RationalMatrix(Integer(2), Integer(5))
      >>> A == loads(dumps(A))  # indirect doctest
      True

sage.matroids.unpickling.unpickle_regular_matroid(version, data)

  Unpickle a RegularMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer (currently 0)

  - `data` – tuple `(A, E, reduced, name)` where `A` is the representation matrix, `E` is the groundset of the matroid, `reduced` is a boolean indicating whether `A` is a reduced matrix, and `name` is a custom name.

  OUTPUT: `RegularMatroid`

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: M = matroids.catalog.R10()
      sage: M == loads(dumps(M))  # indirect doctest
      True
      sage: M.rename('R_{10}')
      sage: loads(dumps(M))
      R_{10}

  Python

      >>> from sage.all import *
      >>> M = matroids.catalog.R10()
      >>> M == loads(dumps(M))  # indirect doctest
      True
      >>> M.rename('R_{10}')
      >>> loads(dumps(M))
      R_{10}

sage.matroids.unpickling.unpickle_ternary_matrix(version, data)

  Reconstruct a `TernaryMatrix` object (internal Sage data structure).

  Warning

  Users should not call this method directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.lean_matrix import *
      sage: A = TernaryMatrix(2, 5)
      sage: A == loads(dumps(A))  # indirect doctest
      True
      sage: C = TernaryMatrix(2, 2, Matrix(GF(3), [[1, 1], [0, 1]]))
      sage: C == loads(dumps(C))
      True

  Python

      >>> from sage.all import *
      >>> from sage.matroids.lean_matrix import *
      >>> A = TernaryMatrix(Integer(2), Integer(5))
      >>> A == loads(dumps(A))  # indirect doctest
      True
      >>> C = TernaryMatrix(Integer(2), Integer(2), Matrix(GF(Integer(3)), [[Integer(1), Integer(1)], [Integer(0), Integer(1)]]))
      >>> C == loads(dumps(C))
      True

sage.matroids.unpickling.unpickle_ternary_matroid(version, data)

  Unpickle a TernaryMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer (currently 0)

  - `data` – tuple `(A, E, B, name)` where `A` is the representation matrix, `E` is the groundset of the matroid, `B` is the currently displayed basis, and `name` is a custom name.

  OUTPUT: `TernaryMatroid`

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.advanced import *
      sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1],
      ....:           [0, 0, 1, 1]]))
      sage: M == loads(dumps(M))  # indirect doctest
      True
      sage: M.rename('U34')
      sage: loads(dumps(M))
      U34

  Python

      >>> from sage.all import *
      >>> from sage.matroids.advanced import *
      >>> M = TernaryMatroid(Matrix(GF(Integer(3)), [[Integer(1), Integer(0), Integer(0), Integer(1)], [Integer(0), Integer(1), Integer(0), Integer(1)],
      ...           [Integer(0), Integer(0), Integer(1), Integer(1)]]))
      >>> M == loads(dumps(M))  # indirect doctest
      True
      >>> M.rename('U34')
      >>> loads(dumps(M))
      U34

sage.matroids.unpickling.unpickle_transversal_matroid(version, data)

  Unpickle a TransversalMatroid.

  Pickling is Python’s term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the `load` and `save` commands, and you should never have to call this function directly.

  INPUT:

  - `version` – integer (currently \(0\))

  - `data` – tuple `(sets, groundset, name)`, where `groundset` is a `frozenset` of elements, and `sets` is a `frozenset` of tuples consisting of a name for the set, and a `frozenset` of groundset elements it contains.

  OUTPUT: `TransversalMatroid`

  Warning

  Users should never call this function directly.

  EXAMPLES:

  Sage

      sage: from sage.matroids.transversal_matroid import *
      sage: sets = [range(6)] * 3
      sage: M = TransversalMatroid(sets)
      sage: M == loads(dumps(M))
      True
      sage: M.rename('U36')
      sage: loads(dumps(M))
      U36

  Python

      >>> from sage.all import *
      >>> from sage.matroids.transversal_matroid import *
      >>> sets = [range(Integer(6))] * Integer(3)
      >>> M = TransversalMatroid(sets)
      >>> M == loads(dumps(M))
      True
      >>> M.rename('U36')
      >>> loads(dumps(M))
      U36