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:

  1. Converting the object into a plain Julia Dict{Symbol,Any} using to_dict.
  2. Serializing this dictionary into the target format (e.g., JSON or BSON).

De-serialization follows the reverse process.

Contents

Dictionary Interface

The core of the serialization system is the Dict interface.

Gridap.Io.to_dictFunction
to_dict(object) -> Dict

Serialize 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.

source
Gridap.Io.from_dictFunction
from_dict(::Type{T}, dict::Dict) where T

De-serialize an object of type T from the dictionary dict.

Values in the dictionary should be native Julia data types. Dictionary keys are Symbols.

source
Gridap.Io.check_dictFunction
check_dict(::Type{T}, dict::Dict) where T

Check 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.

source

JSON

Functions for converting objects to and from JSON (JavaScript Object Notation) strings and files.

Gridap.Io.to_jsonFunction
to_json(object; kwargs...) -> String

Serializes object into a JSON-formatted string.

Keyword arguments are passed to JSON.json.

source
Gridap.Io.from_jsonFunction
from_json(::Type{T}, s::AbstractString; kwargs...) where T

De-serializes a JSON string s into an object of type T.

Keyword arguments are passed to JSON.parse.

source
Gridap.Io.to_json_fileFunction
to_json_file(object, path::AbstractString; kwargs...)

Serializes object into a JSON file.

Keyword arguments are passed to JSON.json.

source
Gridap.Io.from_json_fileFunction
from_json_file(::Type{T}, path::AbstractString; kwargs...) where T

De-serializes a JSON file into an object of type T.

Keyword arguments are passed to JSON.parsefile.

source

BSON

Functions for binary JSON (BSON) serialization, which can be more efficient for large datasets.

JLD2

Functions for JLD2 (Julia Data Format) serialization, a HDF5-compatible format for Julia.

Gridap.Io.to_jld2_fileFunction
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.

source
Gridap.Io.from_jld2_fileFunction
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.

source
from_jld2_file(::Type{T}, path::AbstractString, dataset::AbstractString="data") where T

Loads an object of type T from a JLD2 file.

Throws an error if the loaded object is not of the expected type.

source