API in Ai4EMetaPSE

index

API

Ai4EMetaPSE.MetaSolutionType
  • script::Expr

  • jm::Ai4EMetaPSE.jsonModel

The solution type.

  • script: the generated code
  • jm: store json file imformation
Ai4EMetaPSE.generatecodeMethod
generatecode(
    io::AbstractString,
    type::Ai4EMetaPSE.jsonModel;
    write2File
) -> MetaSolution

To read the json file and return MetaSolution type

  • io: Json file name or json strings
  • type: The type of json, CommonJson , ModelJson and so on.
  • write2File: The name of script to be generated or nothing. If passing nothing, it will not generate script. Default: nothing

Examples:

str = """{
    "name": "Name",
    "pkgs": [
        "ModelingToolkit",
        "DifferentialEquations"
    ],
    "variables": [
        "x(t) = 1.0",
        "y(t) = 1.0",
        "z(t) = 2.0"
    ],
    "parameters": [
        "σ = 1.0",
        "ρ = 3.0",
        "β = 5.0" 
    ],
    "equations": [
        "der(x) = σ*(y - x)",
        "der(y) = x*(ρ - z) - y",
        "der(z) = x*y - β*z"
    ],
    "u0": [
        "x => 1.0",
        "y => 2.0",
        "z => 3.0"
    ],
    "timespan": [0,1,0.1],
    "solver": "Rosenbrock23"
}"""
solution = generatecode(str, CommonJson(); write2File="s.jl")
Ai4EMetaPSE.json2juliaMethod
json2julia(io::AbstractString) -> Expr

json2julia converts a JSON string to a Julia expression.

Examples:

file = joinpath(@__DIR__, "JsonFiles/julia2jsonTest1.json")
ex = json2julia(file)
Ai4EMetaPSE.julia2jsonMethod
julia2json(str::String) -> Dict{Symbol, Any}

julia2json converts a Julia expression to a JSON string.

Examples:

julia2json accepts a string or an expression.

ex = "function f(x)
x + 1
end" |> julia2json
JSON3.pretty(file, ex)
ex = :(function f(x)
x + 1
end) |> julia2json
JSON3.pretty(file, ex)

julia2json can also be used as a macro

s = @julia2json function f(x)
    x + 1
end
JSON3.pretty(file, s)