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)[source]¶
- 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 - loadand- savecommands, 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- Eis the groundset of the matroid,- Ris the rank,- nameis a custom name, and- BBis the bitpacked list of bases, as pickled by Sage’s- bitset_pickle.
 - OUTPUT: matroid - Warning - Users should never call this function directly. - EXAMPLES: - sage: from sage.matroids.advanced import * sage: M = BasisMatroid(matroids.catalog.Vamos()) sage: M == loads(dumps(M)) # indirect doctest True - >>> 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)[source]¶
- Reconstruct a - BinaryMatrixobject (internal Sage data structure).- Warning - Users should not call this method directly. - EXAMPLES: - 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 - >>> 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)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer (currently 0)
- data– tuple- (A, E, B, name)where- Ais the representation matrix,- Eis the groundset of the matroid,- Bis the currently displayed basis, and- nameis a custom name.- OUTPUT: - BinaryMatroid
 - Warning - Users should never call this function directly. - EXAMPLES: - 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 - >>> 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)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer; expected to be 0
- data– tuple- (E, CC, name)in which- Eis the groundset of the matroid,- CCis the dictionary of circuit closures, and- nameis a custom name.
 - OUTPUT: matroid - Warning - Users should never call this function directly. - EXAMPLES: - sage: M = matroids.catalog.Vamos() sage: M == loads(dumps(M)) # indirect doctest True - >>> from sage.all import * >>> M = matroids.catalog.Vamos() >>> M == loads(dumps(M)) # indirect doctest True 
- sage.matroids.unpickling.unpickle_circuits_matroid(version, data)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer; expected to be 0
- data– tuple- (E, C, name)in which- Eis the groundset of the matroid,- Cis the list of circuits , and- nameis a custom name.
 - OUTPUT: matroid - Warning - Users should never call this function directly. - EXAMPLES: - sage: M = matroids.Theta(5) sage: M == loads(dumps(M)) # indirect doctest True - >>> from sage.all import * >>> M = matroids.Theta(Integer(5)) >>> M == loads(dumps(M)) # indirect doctest True 
- sage.matroids.unpickling.unpickle_dual_matroid(version, data)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer; expected to be 0
- data– tuple- (M, name)in which- Mis the internal matroid, and- nameis a custom name
 - OUTPUT: matroid - Warning - Users should not call this function directly. Instead, use load/save. - EXAMPLES: - sage: M = matroids.catalog.Vamos().dual() sage: M == loads(dumps(M)) # indirect doctest True - >>> from sage.all import * >>> M = matroids.catalog.Vamos().dual() >>> M == loads(dumps(M)) # indirect doctest True 
- sage.matroids.unpickling.unpickle_flats_matroid(version, data)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer; expected to be 0
- data– tuple- (E, F, name)in which- Eis the groundset of the matroid,- Fis the dictionary of flats, and- nameis a custom name.
 - OUTPUT: matroid - Warning - Users should never call this function directly. - EXAMPLES: - sage: from sage.matroids.flats_matroid import FlatsMatroid sage: M = FlatsMatroid(matroids.catalog.Vamos()) sage: M == loads(dumps(M)) # indirect doctest True - >>> 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)[source]¶
- 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 - loadand- savecommands, 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- Dis a loopless DiGraph representing the gammoid,- rootsis a subset of the vertices,- Eis the groundset of the matroid, and- nameis a custom name.
 - OUTPUT: matroid - Warning - Users should never call this function directly. - EXAMPLES: - sage: from sage.matroids.gammoid import Gammoid sage: M = Gammoid(digraphs.TransitiveTournament(5), roots=[3, 4]) sage: M == loads(dumps(M)) # indirect doctest True - >>> 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)[source]¶
- Reconstruct a - GenericMatrixobject (internal Sage data structure).- Warning - Users should not call this method directly. - EXAMPLES: - sage: from sage.matroids.lean_matrix import * sage: A = GenericMatrix(2, 5, ring=QQ) sage: A == loads(dumps(A)) # indirect doctest True - >>> 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)[source]¶
- 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 - loadand- savecommands, 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: M = Matroid(graphs.DiamondGraph()) # needs sage.graphs sage: M == loads(dumps(M)) # needs sage.graphs True - >>> 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)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer (currently 0)
- data– tuple- (A, E, reduced, name)where- Ais the representation matrix,- Eis the groundset of the matroid,- reducedis a boolean indicating whether- Ais a reduced matrix, and- nameis a custom name.
 - OUTPUT: - LinearMatroid- Warning - Users should never call this function directly. - EXAMPLES: - 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 - >>> 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)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer; currently \(0\)
- data– tuple- (M, C, D, name), where- Mis the original matroid of which the output is a minor,- Cis the set of contractions,- Dis the set of deletions, and- nameis a custom name.
 - OUTPUT: - MinorMatroid- Warning - Users should never call this function directly. - EXAMPLES: - sage: M = matroids.catalog.Vamos().minor('abc', 'g') sage: M == loads(dumps(M)) # indirect doctest True - >>> 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)[source]¶
- Reconstruct an - PlusMinusOneMatrixobject (internal Sage data structure).- Warning - Users should not call this method directly. - EXAMPLES: - sage: from sage.matroids.lean_matrix import * sage: A = PlusMinusOneMatrix(2, 5) sage: A == loads(dumps(A)) # indirect doctest True - >>> 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)[source]¶
- Reconstruct a - QuaternaryMatrixobject (internal Sage data structure).- Warning - Users should not call this method directly. - EXAMPLES: - 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 - >>> 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)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer (currently 0)
- data– tuple- (A, E, B, name)where- Ais the representation matrix,- Eis the groundset of the matroid,- Bis the currently displayed basis, and- nameis a custom name.
 - OUTPUT: - TernaryMatroid- Warning - Users should never call this function directly. - EXAMPLES: - 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] - >>> 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)[source]¶
- Reconstruct a - sage.matroids.lean_matrix.RationalMatrixobject (internal Sage data structure).- Warning - Users should not call this method directly. - EXAMPLES: - sage: from sage.matroids.lean_matrix import RationalMatrix sage: A = RationalMatrix(2, 5) sage: A == loads(dumps(A)) # indirect doctest True - >>> 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)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer (currently 0)
- data– tuple- (A, E, reduced, name)where- Ais the representation matrix,- Eis the groundset of the matroid,- reducedis a boolean indicating whether- Ais a reduced matrix, and- nameis a custom name.
 - OUTPUT: - RegularMatroid- Warning - Users should never call this function directly. - EXAMPLES: - sage: M = matroids.catalog.R10() sage: M == loads(dumps(M)) # indirect doctest True sage: M.rename('R_{10}') sage: loads(dumps(M)) R_{10} - >>> 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)[source]¶
- Reconstruct a - TernaryMatrixobject (internal Sage data structure).- Warning - Users should not call this method directly. - EXAMPLES: - 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 - >>> 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)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer (currently 0)
- data– tuple- (A, E, B, name)where- Ais the representation matrix,- Eis the groundset of the matroid,- Bis the currently displayed basis, and- nameis a custom name.
 - OUTPUT: - TernaryMatroid- Warning - Users should never call this function directly. - EXAMPLES: - 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 - >>> 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)[source]¶
- 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 - loadand- savecommands, and you should never have to call this function directly.- INPUT: - version– integer (currently \(0\))
- data– tuple- (sets, groundset, name), where- groundsetis a- frozensetof elements, and- setsis a- frozensetof tuples consisting of a name for the set, and a- frozensetof groundset elements it contains.
 - OUTPUT: - TransversalMatroid- Warning - Users should never call this function directly. - EXAMPLES: - 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 - >>> 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