diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index e2b2130..6c4db8d 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-02-02T22:10:00","documenter_version":"1.2.1"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-02-02T22:48:06","documenter_version":"1.2.1"}} \ No newline at end of file diff --git a/dev/api/index.html b/dev/api/index.html index 46def84..4532193 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -1,5 +1,5 @@ -Library Reference · SyntacticModels.jl

Library Reference

Base.DictMethod
Dict(x::AbstractTerm)

to register your type with JSON3, you need to overload JSON3.write to use this Dict approach. we only overload the Dict function for our type Formula, so this is not piracy.

source
SyntacticModels.SyntacticModelsBase.AbstractTermType
AbstractTerm

The super type for all SyntacticModels types. This abstract type exists so that we can write generic methods that work on any term in any of the domain specific syntaxes. For example, serializing to a Dictionary uses some reflection snippet that works for arbitrary types, but we only want to apply it to things that should be serialized like a Term.

source
JSON3.writeMethod
JSON3.write

Now JSON3.write(f) puts the type information in our reserved field.

source
StructTypes.subtypekeyMethod
StructTypes.subtypekey

This is how you tell StructTypes where to look for the name of a type when reading the type back in from JSON.

source
SyntacticModels.SyntacticModelsBase._dictMethod
_dict(x::T) where T <: AbstractTerm

We are going to convert our structs to Dict before we call JSON3.write and add the type information in a generic construction. This uses some reflection to ask the julia type for its fieldnames and then use those as the keys in the Dict. We use splatting, so don't make a struct with more than 32 fields if you want to go fast. We use this _dict function to avoid an "I'm the captain now" level of type piracy.

source

UWDs

SyntacticModels.ASKEMUWDs.UWDTermType
UWDTerm

Term specifying UWD.

Subtypes

  1. UWDModel: A header and UWD Expr
  2. UWDExpr: A Context of variables and a list of statements defining a UWD
  3. Statement: R(x,y,z) a relation that acts on its arguments (which are Vars)

Example

To specify the following relation macro:

@relation (x:X, z:Z) where y:Y begin
+Library Reference · SyntacticModels.jl

Library Reference

Base.DictMethod
Dict(x::AbstractTerm)

to register your type with JSON3, you need to overload JSON3.write to use this Dict approach. we only overload the Dict function for our type Formula, so this is not piracy.

source
SyntacticModels.SyntacticModelsBase.AbstractTermType
AbstractTerm

The super type for all SyntacticModels types. This abstract type exists so that we can write generic methods that work on any term in any of the domain specific syntaxes. For example, serializing to a Dictionary uses some reflection snippet that works for arbitrary types, but we only want to apply it to things that should be serialized like a Term.

source
JSON3.writeMethod
JSON3.write

Now JSON3.write(f) puts the type information in our reserved field.

source
StructTypes.subtypekeyMethod
StructTypes.subtypekey

This is how you tell StructTypes where to look for the name of a type when reading the type back in from JSON.

source
SyntacticModels.SyntacticModelsBase._dictMethod
_dict(x::T) where T <: AbstractTerm

We are going to convert our structs to Dict before we call JSON3.write and add the type information in a generic construction. This uses some reflection to ask the julia type for its fieldnames and then use those as the keys in the Dict. We use splatting, so don't make a struct with more than 32 fields if you want to go fast. We use this _dict function to avoid an "I'm the captain now" level of type piracy.

source

UWDs

SyntacticModels.ASKEMUWDs.UWDTermType
UWDTerm

Term specifying UWD.

Subtypes

  1. UWDModel: A header and UWD Expr
  2. UWDExpr: A Context of variables and a list of statements defining a UWD
  3. Statement: R(x,y,z) a relation that acts on its arguments (which are Vars)

Example

To specify the following relation macro:

@relation (x:X, z:Z) where y:Y begin
   R(x,y)
   S(y,z)
   T(z,y,u)
@@ -11,8 +11,8 @@
 s = [Statement(:R, [v1,v2]),
   Statement(:S, [v2,v3]),
   Statement(:T, [v3,v2, v4])]
-u = UWDExpr(c, s)
source
SyntacticModels.ASKEMUWDs.VarType
Var

Variables of a UWD. Types are the domain types, ScalarField, VectorField, Dual1Form, Primal2Form NOT Float64,Complex128

Subtypes include:

  1. Untyped(var::Symbol)
  2. Typed(var::Symbol, type::Symbol)

which are used for representing typed or untyped variables.

source
Base.showMethod
show(io::IO, s::UWDTerm)

generates a human readable string of the UWDTerm (or any sub-term).

source

Decapodes

Composites

SyntacticModels.ASKEMUWDs.VarType
Var

Variables of a UWD. Types are the domain types, ScalarField, VectorField, Dual1Form, Primal2Form NOT Float64,Complex128

Subtypes include:

  1. Untyped(var::Symbol)
  2. Typed(var::Symbol, type::Symbol)

which are used for representing typed or untyped variables.

source
Base.showMethod
show(io::IO, s::UWDTerm)

generates a human readable string of the UWDTerm (or any sub-term).

source

Decapodes

Composites

SyntacticModels.Composites.CompositeModelType
CompositeModel
@data CompositeModel <: AbstractTerm begin
   OpenModel(model::ASKEMDecapodes.ASKEMDecaExpr, interface::Vector{Symbol})
   OpenDecapode(model::ASKEMDecapodes.ASKEMDecapode, interface::Vector{Symbol})
   CompositeModelExpr(header::Header, composition_pattern::UWDExpr, components::Vector{CompositeModel})
-end
source
Catlab.WiringDiagrams.WiringDiagramAlgebras.oapplyMethod
Catlab.oapply(m::CompositeModel)

CompositeModels can be flattened into a single level of model with the oapply function.

Warning

Because the oapply algorithm operates on the compute graph representation of the equations, it does not produce syntactic equations. Calls to oapply produce instances of OpenDecapode and not DecaExpr. Software that expects to consume decapodes should plan to interact with both forms.

source
SyntacticModels.Composites.interfaceMethod
interface(m::CompositeModel)

Extract the interface of a composite model. If the model is open, then it is the feet of the cospan. If it is a Composite, then it is the context of the uwd.

source
+end
source
Catlab.WiringDiagrams.WiringDiagramAlgebras.oapplyMethod
Catlab.oapply(m::CompositeModel)

CompositeModels can be flattened into a single level of model with the oapply function.

Warning

Because the oapply algorithm operates on the compute graph representation of the equations, it does not produce syntactic equations. Calls to oapply produce instances of OpenDecapode and not DecaExpr. Software that expects to consume decapodes should plan to interact with both forms.

source
SyntacticModels.Composites.interfaceMethod
interface(m::CompositeModel)

Extract the interface of a composite model. If the model is open, then it is the feet of the cospan. If it is a Composite, then it is the context of the uwd.

source
diff --git a/dev/generated/composite_models_examples/index.html b/dev/generated/composite_models_examples/index.html index 44e2f14..8cf2e12 100644 --- a/dev/generated/composite_models_examples/index.html +++ b/dev/generated/composite_models_examples/index.html @@ -753,4 +753,4 @@ op1 : Op1 → Operator = [:∂ₜ, :∂ₜ, :λ] op2 : Op2 → Operator = [:*, :*, :*, :-] type : Var → Type = [:Form0, :Form0, :Constant, :infer, :infer, :Literal, :Form0, :Constant, :Form0, :Parameter, :Form0, :Constant, :infer, :Form0] - name : Var → Name = [:X, :V, :oscillator_k, :oscillator_mult_1, :oscillator_V̇, Symbol("-1"), :heating_Q₊, :heating_drag_κ, :heating_Q₋, :heating_cooling_Q₀, :Q, :heating_cooling_λ, Symbol("heating_cooling_•1"), :heating_Q̇], SyntacticModels.AMR.Annotation{Symbol, Symbol}[]) + name : Var → Name = [:X, :V, :oscillator_k, :oscillator_mult_1, :oscillator_V̇, Symbol("-1"), :heating_Q₊, :heating_drag_κ, :heating_Q₋, :heating_cooling_Q₀, :Q, :heating_cooling_λ, Symbol("heating_cooling_•1"), :heating_Q̇], SyntacticModels.AMR.Annotation{Symbol, Symbol}[]) diff --git a/dev/generated/decapodes_examples/index.html b/dev/generated/decapodes_examples/index.html index 3eced14..93a16d3 100644 --- a/dev/generated/decapodes_examples/index.html +++ b/dev/generated/decapodes_examples/index.html @@ -469,4 +469,4 @@ ], "Name": [ ] -} +} diff --git a/dev/generated/uwd_examples/index.html b/dev/generated/uwd_examples/index.html index d38f29f..1275007 100644 --- a/dev/generated/uwd_examples/index.html +++ b/dev/generated/uwd_examples/index.html @@ -273,4 +273,4 @@ UWD: { R(x:X, y:Y) S(y:Y, z:Z) - T(z:Z, y:Y, u) } where {x:X, z:Z}

And write that model in JSON

s = JSON3.write(mexpr)
"{\"uwd\":{\"statements\":[{\"variables\":[{\"var\":\"x\",\"type\":\"X\",\"_type\":\"Typed\"},{\"var\":\"y\",\"type\":\"Y\",\"_type\":\"Typed\"}],\"_type\":\"Statement\",\"relation\":\"R\"},{\"variables\":[{\"var\":\"y\",\"type\":\"Y\",\"_type\":\"Typed\"},{\"var\":\"z\",\"type\":\"Z\",\"_type\":\"Typed\"}],\"_type\":\"Statement\",\"relati" ⋯ 216 bytes ⋯ "\"},{\"var\":\"z\",\"type\":\"Z\",\"_type\":\"Typed\"}],\"_type\":\"UWDExpr\"},\"header\":{\"description\":\"A demo UWD showing generic relation composition\",\"name\":\"rst_relation\",\"_type\":\"Header\",\"model_version\":\"v0.1\",\"schema\":\"modelreps.io/UWD\",\"schema_name\":\"UWDExpr\"},\"_type\":\"UWDModel\"}"

Just as check, the headers should be preserved.

@test JSON3.write(JSON3.read(s, UWDModel)) == JSON3.write(mexpr)
Test Passed
+ T(z:Z, y:Y, u) } where {x:X, z:Z}

And write that model in JSON

s = JSON3.write(mexpr)
"{\"uwd\":{\"statements\":[{\"variables\":[{\"var\":\"x\",\"type\":\"X\",\"_type\":\"Typed\"},{\"var\":\"y\",\"type\":\"Y\",\"_type\":\"Typed\"}],\"_type\":\"Statement\",\"relation\":\"R\"},{\"variables\":[{\"var\":\"y\",\"type\":\"Y\",\"_type\":\"Typed\"},{\"var\":\"z\",\"type\":\"Z\",\"_type\":\"Typed\"}],\"_type\":\"Statement\",\"relati" ⋯ 216 bytes ⋯ "\"},{\"var\":\"z\",\"type\":\"Z\",\"_type\":\"Typed\"}],\"_type\":\"UWDExpr\"},\"header\":{\"description\":\"A demo UWD showing generic relation composition\",\"name\":\"rst_relation\",\"_type\":\"Header\",\"model_version\":\"v0.1\",\"schema\":\"modelreps.io/UWD\",\"schema_name\":\"UWDExpr\"},\"_type\":\"UWDModel\"}"

Just as check, the headers should be preserved.

@test JSON3.write(JSON3.read(s, UWDModel)) == JSON3.write(mexpr)
Test Passed
diff --git a/dev/index.html b/dev/index.html index d5be56e..1ef30c2 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -SyntacticModels.jl · SyntacticModels.jl

SyntacticModels.jl

SyntacticModels.jl is a Julia library for representing models as syntactic expressions.

The driving example for this library is the need to interoperate models between programming languages in the DARPA ASKEM Program. The AlgebraicJulia ecosystem includes some great tools for specifying modeling languages, but they are deeply connected to the Julia language. This package aims to provide simple tools for specifying domain specific programming languages that can be used to exchange the specification of scientific models between host languages.

We heavily use the MLStyle.jl package for defining Algebraic Data Types so you should familiarize yourself with those concepts before reading on in this documentation.

+SyntacticModels.jl · SyntacticModels.jl

SyntacticModels.jl

SyntacticModels.jl is a Julia library for representing models as syntactic expressions.

The driving example for this library is the need to interoperate models between programming languages in the DARPA ASKEM Program. The AlgebraicJulia ecosystem includes some great tools for specifying modeling languages, but they are deeply connected to the Julia language. This package aims to provide simple tools for specifying domain specific programming languages that can be used to exchange the specification of scientific models between host languages.

We heavily use the MLStyle.jl package for defining Algebraic Data Types so you should familiarize yourself with those concepts before reading on in this documentation.