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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer, expected to be 0data
– a tuple(E, R, name, BB)
in whichE
is the groundset of the matroid,R
is the rank,name
is a custom name, andBB
is the bitpacked list of bases, as pickled by Sage’sbitset_pickle
.
OUTPUT:
A 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
BinaryMatrix
object (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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer (currently 0).data
– a tuple(A, E, B, name)
whereA
is the representation matrix,E
is the groundset of the matroid,B
is the currently displayed basis, andname
is a custom name.OUTPUT:
A
BinaryMatroid
instance.
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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer, expected to be 0data
– a tuple(E, CC, name)
in whichE
is the groundset of the matroid,CC
is the dictionary of circuit closures, andname
is a custom name.
OUTPUT:
A 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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer, expected to be 0data
– a tuple(E, C, name)
in whichE
is the groundset of the matroid,C
is the list of circuits , andname
is a custom name.
OUTPUT:
A 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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer, expected to be 0data
– a tuple(M, name)
in whichM
is the internal matroid, andname
is a custom name.
OUTPUT:
A 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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer, expected to be 0data
– a tuple(E, F, name)
in whichE
is the groundset of the matroid,F
is the dictionary of flats, andname
is a custom name.
OUTPUT:
A 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_generic_matrix(version, data)[source]#
Reconstruct a
GenericMatrix
object (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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer (currently 0).data
– a tuple consisting of a SageMath graph and a name.
OUTPUT:
A
GraphicMatroid
instance.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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer (currently 0).data
– a tuple(A, E, reduced, name)
whereA
is the representation matrix,E
is the groundset of the matroid,reduced
is a boolean indicating whetherA
is a reduced matrix, andname
is a custom name.
OUTPUT:
A
LinearMatroid
instance.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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer, currently \(0\).data
– a tuple(M, C, D, name)
, whereM
is the original matroid of which the output is a minor,C
is the set of contractions,D
is the set of deletions, andname
is a custom name.
OUTPUT:
A
MinorMatroid
instance.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
PlusMinusOneMatrix
object (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
QuaternaryMatrix
object (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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer (currently 0).data
– a tuple(A, E, B, name)
whereA
is the representation matrix,E
is the groundset of the matroid,B
is the currently displayed basis, andname
is a custom name.
OUTPUT:
A
TernaryMatroid
instance.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.RationalMatrix
object (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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer (currently 0).data
– a tuple(A, E, reduced, name)
whereA
is the representation matrix,E
is the groundset of the matroid,reduced
is a boolean indicating whetherA
is a reduced matrix, andname
is a custom name.
OUTPUT:
A
RegularMatroid
instance.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
TernaryMatrix
object (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
load
andsave
commands, and you should never have to call this function directly.INPUT:
version
– an integer (currently 0).data
– a tuple(A, E, B, name)
whereA
is the representation matrix,E
is the groundset of the matroid,B
is the currently displayed basis, andname
is a custom name.
OUTPUT:
A
TernaryMatroid
instance.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