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.
saveFunction
save(io::IO, obj::Any)
save(filename::String, obj::Any)

Save an object T to the given io stream respectively to the file filename.

See load.

Examples

julia> save("/tmp/fourtitwo.json", 42);

julia> load("/tmp/fourtitwo.json")
42
source
loadFunction
load(io::IO; parent::Any = nothing, type::Any = nothing)
load(filename::String; parent::Any = nothing, type::Any = nothing)

Load the object stored in the given io stream respectively in the file filename.

If parent is specified, then the root object of the loaded data either will have this as its parent, or it is a container such as Vector and Tuple, then the parent of the entries will be set to parent.

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", parent=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", parent=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
source
is_basic_serialization_typeFunction
is_basic_serialization_type(::Type)

During the serialization of types of the form Vector{T}, entries of type T will either be serialized as strings if is_basic_serialization_type returns true, or serialized as a dict provided the serialization for such a T exists. If Vector{T} is serialized with is_basic_serialization_type(T) = true then the entry_type keyword is used to store the type T as a property of the vector.

Examples

julia> is_basic_serialization_type(ZZRingElem)
true
source

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