API in Ai4EMetaPSE
index
Ai4EMetaPSE.MetaSolution
Ai4EMetaPSE.evalSolution
Ai4EMetaPSE.generatecode
Ai4EMetaPSE.getscript
Ai4EMetaPSE.json2julia
Ai4EMetaPSE.julia2json
API
Ai4EMetaPSE.MetaSolution
— Typescript::Expr
jm::Ai4EMetaPSE.jsonModel
The solution type.
script
: the generated codejm
: store json file imformation
Ai4EMetaPSE.evalSolution
— MethodevalSolution(solution::MetaSolution) -> Any
To eval
the script in MetaSolution
at Main
solution
: the result fromgeneratecode
Ai4EMetaPSE.generatecode
— Methodgeneratecode(
io::AbstractString,
type::Ai4EMetaPSE.jsonModel;
write2File
) -> MetaSolution
To read the json file and return MetaSolution
type
io
: Json file name or json stringstype
: 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.getscript
— Methodgetscript(solution::MetaSolution) -> Expr
To get the script in MetaSolution
solution
: the result fromgeneratecode
Ai4EMetaPSE.json2julia
— Methodjson2julia(io::AbstractString) -> Expr
json2julia converts a JSON string to a Julia expression.
Examples:
file = joinpath(@__DIR__, "JsonFiles/julia2jsonTest1.json")
ex = json2julia(file)
Ai4EMetaPSE.julia2json
— Methodjulia2json(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)