Serialization
Introduction
For some of our datatypes we provide a way to save them in and load them from JSON format. This is still experimental and it will take some time until all corners of OSCAR are covered by this effort. The goal of this effort is threefold:
- Avoid recomputation by providing an easy way to store data.
- Increase portability by giving a convenient possibility to transport data.
- Increase overall software quality by testing against existing data and tracking errors through data computed by different versions.
save
— Functionsave(io::IO, obj::Any; metadata::MetaData=nothing)
save(filename::String, obj::Any, metadata::MetaData=nothing)
Save an object T
to the given io stream respectively to the file filename
.
See load
.
Examples
julia> meta = metadata(author_orcid="0000-0000-0000-0042", name="the meaning of life the universe and everything")
Oscar.MetaData("0000-0000-0000-0042", "the meaning of life the universe and everything")
julia> save("/tmp/fourtitwo.json", 42; metadata=meta);
julia> load("/tmp/fourtitwo.json")
42
load
— Functionload(io::IO; params::Any = nothing, type::Any = nothing)
load(filename::String; params::Any = nothing, type::Any = nothing)
Load the object stored in the given io stream respectively in the file filename
.
If params
is specified, then the root object of the loaded data either will attempt a load using these parameters. In the case of Rings this results in setting its parent, or in the case of a container of ring types such as Vector
or Tuple
, then the parent of the entries will be set using their params
.
If a type T
is given then attempt to load the root object of the data being loaded with this type; if this fails, an error is thrown.
See save
.
Examples
julia> save("/tmp/fourtitwo.json", 42);
julia> load("/tmp/fourtitwo.json")
42
julia> load("/tmp/fourtitwo.json"; type=Int64)
42
julia> R, x = QQ["x"]
(Univariate polynomial ring in x over QQ, x)
julia> p = x^2 - x + 1
x^2 - x + 1
julia> save("/tmp/p.json", p)
julia> p_loaded = load("/tmp/p.json", params=R)
x^2 - x + 1
julia> parent(p_loaded) === R
true
julia> save("/tmp/p_v.json", [p, p])
julia> loaded_p_v = load("/tmp/p_v.json", params=R)
2-element Vector{QQPolyRingElem}:
x^2 - x + 1
x^2 - x + 1
julia> parent(loaded_p_v[1]) === parent(loaded_p_v[2]) === R
true
Objects that can be serialized
In this section we will list objects that may be (de-)serialized. This list may be incomplete.
Many low level objects may be stored and these in turn allow serializing higher level objects. Such low level objects are various types of matrices, vectors and sets.
Combinatorics
Graph
SimplicialComplex
Commutative Algebra
Ideal
Polynomial
polynomial_ring
Polyhedral Geometry
Cone
LinearProgram
PolyhedralFan
PolyhedralComplex
Polyhedron
SubdivisionOfPoints
Toric Geometry
NormalToricVariety
ToricDivisor
Tropical Geometry
TropicalCurve
TropicalHypersurface