Gridap.Io
The Gridap.Io module provides a unified interface for the serialization and de-serialization of Gridap objects (such as models, fields, and finite element spaces) into various formats, including JSON, BSON, and JLD2.
Most serialization processes in Gridap follow a two-step approach:
- Converting the object into a plain Julia
Dict{Symbol,Any}usingto_dict. - Serializing this dictionary into the target format (e.g., JSON or BSON).
De-serialization follows the reverse process.
Gridap.Io — Module
This module provides a set of utilities to read and write data in various formats, including JSON, BSON, JLD2, and more.
Exported names
from_bson_file, from_dict, from_jld2_file, from_json, from_json_file, to_bson_file, to_dict, to_jld2_file, to_json, to_json_file,
Contents
Dictionary Interface
The core of the serialization system is the Dict interface.
Gridap.Io.to_dict — Function
to_dict(object) -> DictSerialize object into a dictionary of type Dict{Symbol,Any}.
Values stored in this dictionary must be native Julia data types (e.g., Real, Integer, String, Vector, Dict). Dictionary keys are Symbols. This is typically the first step in serializing an object to formats like JSON or BSON.
Gridap.Io.from_dict — Function
from_dict(::Type{T}, dict::Dict) where TDe-serialize an object of type T from the dictionary dict.
Values in the dictionary should be native Julia data types. Dictionary keys are Symbols.
Gridap.Io.check_dict — Function
check_dict(::Type{T}, dict::Dict) where TCheck if the dictionary dict is valid for an object of type T.
Returns successfully if the dictionary is compatible with the type T, otherwise throws an error.
JSON
Functions for converting objects to and from JSON (JavaScript Object Notation) strings and files.
Gridap.Io.to_json — Function
to_json(object; kwargs...) -> StringSerializes object into a JSON-formatted string.
Keyword arguments are passed to JSON.json.
Gridap.Io.from_json — Function
from_json(::Type{T}, s::AbstractString; kwargs...) where TDe-serializes a JSON string s into an object of type T.
Keyword arguments are passed to JSON.parse.
Gridap.Io.to_json_file — Function
to_json_file(object, path::AbstractString; kwargs...)Serializes object into a JSON file.
Keyword arguments are passed to JSON.json.
Gridap.Io.from_json_file — Function
from_json_file(::Type{T}, path::AbstractString; kwargs...) where TDe-serializes a JSON file into an object of type T.
Keyword arguments are passed to JSON.parsefile.
BSON
Functions for binary JSON (BSON) serialization, which can be more efficient for large datasets.
Gridap.Io.to_bson_file — Function
to_bson_file(object, path::AbstractString)Serializes object into a BSON file.
Gridap.Io.from_bson_file — Function
from_bson_file(::Type{T}, path::AbstractString) where TDe-serializes a BSON file into an object of type T.
JLD2
Functions for JLD2 (Julia Data Format) serialization, a HDF5-compatible format for Julia.
Gridap.Io.to_jld2_file — Function
to_jld2_file(object, path::AbstractString, dataset::AbstractString="data")Serializes object into a JLD2 file.
The dataset parameter specifies the name/root location of the data inside the file.
Gridap.Io.from_jld2_file — Function
from_jld2_file(path::AbstractString, dataset::AbstractString="data")Loads an object from a JLD2 file.
The dataset parameter specifies the name/root location of the data inside the file.
from_jld2_file(::Type{T}, path::AbstractString, dataset::AbstractString="data") where TLoads an object of type T from a JLD2 file.
Throws an error if the loaded object is not of the expected type.