Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP update to use InterTypes #29

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
883a465
Started making versions with InterTypes, amr.it and decapodes.it, and…
p-stokes Dec 1, 2023
1c91145
Fixed typos in decapodes.it and updated intertype_examples.jl
p-stokes Dec 1, 2023
81d1d9c
Removed redundant Header def from decapodes.it and added id field to …
p-stokes Dec 1, 2023
6f3df6f
Added decapode parsing functions and test example for ASKEMDecaExpr w…
p-stokes Dec 1, 2023
84a37dc
Started setting up src files to export the intertype structures. Star…
p-stokes Dec 4, 2023
361199c
uwd write and read test example working. needed to change write_json_…
p-stokes Dec 4, 2023
aa5cf1a
Added intertype version of SummationDecapode function and its helpers…
p-stokes Dec 4, 2023
cd83f9d
Added intertype structs for SummationDecapode. It will load the inter…
p-stokes Dec 5, 2023
692a242
Added/updated functions to make intertype SummationDecapode. No longe…
p-stokes Dec 5, 2023
2d073e3
Started factoring amr and uwd parts into source and test files, and u…
p-stokes Dec 5, 2023
a4b61af
Updated Project.toml
p-stokes Dec 5, 2023
c0a34fb
Factored decapodes part into src and test. Again had to change AMR na…
p-stokes Dec 5, 2023
f6e4db1
Started making intertype version for composite_models.
p-stokes Dec 5, 2023
eaa5c91
Updated composite_models_it src and test. Intertype version of oapply…
p-stokes Dec 6, 2023
aed4d45
Started working on intertype version of ACSetSpec and other ADT code …
p-stokes Dec 6, 2023
744bbca
Moved amr_it.jl contents into amr.jl to better view differences.
p-stokes Dec 6, 2023
d1ad500
Moved contents of decapodes_it.jl and uwd_it.jl files to respective o…
p-stokes Dec 6, 2023
8c4b047
Moved contents of composite_models_it.jl to original file for easier …
p-stokes Dec 6, 2023
f4fe83c
Moved contents of _it_ex.jl files to their corresponding _examples.jl…
p-stokes Dec 6, 2023
19f98d2
deleted intertype versions of amr.jl and decapodes.jl
p-stokes Dec 7, 2023
233896f
Removed remaining intertype versions of src and test files for easier…
p-stokes Dec 7, 2023
c2cc82b
Removed unnecessary imports from test examples.
p-stokes Dec 7, 2023
bac39db
Updated Project.toml for docs.
p-stokes Dec 7, 2023
0274d67
Updated decapodes example doc.
p-stokes Dec 7, 2023
37e6398
Cleaned up imports and qualification of type names in src files. Remo…
p-stokes Dec 7, 2023
bbcb53d
Updated name qualifications in test examples.
p-stokes Dec 8, 2023
5a9f95b
Removed new id field from Header. Now same as before the PR. Will mak…
p-stokes Dec 8, 2023
7785c96
Made oapply workaround -- it_to_orig converts an intertype summation …
p-stokes Dec 11, 2023
6feef74
Made coversion from Decapodes.SummationDecapode to intertype version.…
p-stokes Dec 11, 2023
ab9a258
Uncommented sm_write_json_model, 2nd write_json_model method and most…
p-stokes Dec 12, 2023
6af6977
Added clarifying comments in composite_models_examples.jl about fixes…
p-stokes Dec 12, 2023
cf77220
Added acsetspec converter from ADTs version to intertype. Updated typ…
p-stokes Dec 14, 2023
403b573
Fixed convert_pair_to_it and changed convert_val_to_it to handle Quot…
p-stokes Dec 14, 2023
dc77e68
Edited load Typing and ASKEModel from dict. Typing part requires Pair…
p-stokes Dec 14, 2023
e07fb29
Corrected amr var name in amr_to_expr. Now, problem with amr_to_expr …
p-stokes Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ Decapodes = "679ab3ea-c928-4fe6-8d59-fd451142d391"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[compat]
ACSets = "0.2"
Catlab = "0.15, 0.16"
Decapodes = "0.5"
Decapodes = "0.4, 0.5"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since code is moved here, do we still need to depend on Decapodes?

JSON = "0.21"
JSON3 = "1"
MLStyle = "0.4"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
SyntacticModels = "22bb929c-8bcf-4852-b455-eb3e1675e09c"
7 changes: 4 additions & 3 deletions docs/literate/decapodes_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ We only look at ordinary differential equations here, but you can think of these

using ..SyntacticModels
using ..SyntacticModels.ASKEMDecapodes
using ..SyntacticModels.ASKEMDecapodes: parse_decapode, SummationDecapode
using ..SyntacticModels.AMR

using MLStyle
using JSON3
using Catlab
using ACSets
using ACSets.JSONACSets
using Decapodes
# using Decapodes
using Test

# Build the heder object describing the model.
Expand All @@ -27,7 +28,7 @@ h = AMR.Header("harmonic_oscillator",
"v1.0")

# The easiest way to write down a DecaExpr is in our DSL and calling the parser.
dexpr = Decapodes.parse_decapode(quote
dexpr = parse_decapode(quote
X::Form0{Point}
V::Form0{Point}

Expand All @@ -44,7 +45,7 @@ mexpr = ASKEMDecaExpr(h, dexpr)
# Convert a the DecaExpr to a SummationDecapode which is the
# combinatorial representation. The converter lives in Decapodes/src/language.jl.

d = Decapodes.SummationDecapode(mexpr.model)
d = SummationDecapode(mexpr.model)

# To visualize the Decapode as a compute graph, you can use Graphviz

Expand Down
102 changes: 102 additions & 0 deletions src/amr.it
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

@sum Args begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being copied from https://github.com/AlgebraicJulia/ACSets.jl/blob/main/src/ADTs.jl#L14?

We should upgrade that code to use InterTypes and then import that usage here.

Value(_1::Symbol)
Kwarg(_1::Symbol, _2::Args)
end

struct Statement
table::Symbol
element::Vector{Args}
end

#=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this?

@sum union_sym_expr begin
sym(s::Symbol)
expr(e::Expr)
end
=#

struct ACSetSpec
acstype::Symbol
body::Vector{Statement}
end

@sum MathML begin
Math(str::String)
Presentation(str::String)
end


struct ExpressionFormula
expression::String
expression_mathml::MathML
end

struct Unit
expression::String
expression_mathml::MathML
end


@sum Distribution begin
StandardUniform(str::String)
Uniform(min::Float64, max::Float64)
StandardNormal(str::String)
Normal(mean::Float64, variance::Float64)
PointMass(value::Float64)
end

struct Observable
id::Symbol
name::String
states::Vector{Symbol}
f::ExpressionFormula
end

@sum Expression begin
Rate(target::Symbol, f::ExpressionFormula)
Initial(target::Symbol, f::ExpressionFormula)
Parameter(id::Symbol, name::String, description::String, units::Unit, value::Float64, distribution::Distribution)
Time(id::Symbol, units::Unit)
end

struct Pair
first::Symbol
second::Symbol
end

@sum Semantic begin
ODEList(statements::Vector{Expression})
ODERecord(rates::Vector{Rate}, initials::Vector{Initial}, parameters::Vector{Parameter}, time::Time)
Typing(system::ACSetSpec, map::Vector{Pair})
end


@sum Note begin
Name(str::String)
Description(str::String)
Grounding(ontology::String, identifier::String)
Units(expression::String)
end

struct Annotation
entity::Symbol
type::Symbol
note::Note
end

struct Header
id::String
name::String
schema::String
description::String
schema_name::String
model_version::String
end


struct ASKEModel
header::Header
model::ACSetSpec
semantics::Vector{Semantic}
end
106 changes: 15 additions & 91 deletions src/amr.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module AMR

export Math, MathML, ExpressionFormula, Unit, Distribution, Observable, Expression,
export amr, Math, MathML, ExpressionFormula, Unit, Distribution, Observable, Expression,
Rate, Initial, Parameter, Time,
StandardUniform, Uniform, StandardNormal, Normal, PointMass,
Semantic, Header, ODERecord, ODEList, Typing, ASKEModel,
distro_string, amr_to_string,
Semantic, Header, ODERecord, ODEList, ASKEModel, # Typing,
distro_string, # amr_to_string,
Annotation, Note, Name, Description, Grounding, Units

using Reexport
Expand All @@ -14,95 +14,17 @@
using ACSets.ACSetInterface
using StructTypes

using ..SyntacticModelsBase

@data MathML <: AbstractTerm begin
Math(String)
Presentation(String)
end

nomath = Math("")

@as_record struct ExpressionFormula{T} <: AbstractTerm
expression::T
expression_mathml::MathML
end

@as_record struct Unit <: AbstractTerm
expression::String
expression_mathml::MathML
end

@intertypes "amr.it" module amr end

nounit = Unit("", nomath)
using .amr

@data Distribution <: AbstractTerm begin
StandardUniform
Uniform(min, max)
StandardNormal
Normal(mean, variance)
PointMass(value)
end

@as_record struct Observable{T <: AbstractTerm}
id::Symbol
name::String
states::Vector{Symbol}
f::ExpressionFormula
end

@data Expression <: AbstractTerm begin
Rate(target::Symbol, f::ExpressionFormula)
Initial(target::Symbol, f::ExpressionFormula)
Parameter(id::Symbol, name::String, description::String, units::Unit, value::Float64, distribution::Distribution)
Time(id::Symbol, units::Unit)
end

@data Semantic <: AbstractTerm begin
ODEList(statements::Vector{Expression})
ODERecord(rates::Vector{Rate}, initials::Vector{Initial}, parameters::Vector{Parameter}, time::Time)
# Metadata
Typing(system::ACSetSpec, map::Vector{Pair})
# Stratification
end

@data Note <: AbstractTerm begin
Name(str::String)
Description(str::String)
Grounding(ontology::String, identifier::String)
Units(expression::String)
end

StructTypes.StructType(::Type{Note}) = StructTypes.AbstractType()
StructTypes.subtypekey(::Type{Note}) = :_type
StructTypes.subtypes(::Type{Note}) =
(Name=Name,Description=Description,Grounding=Grounding,Units=Units,)

@as_record struct Annotation{E,T} <: AbstractTerm
entity::E
type::T
note::Note
end

@as_record struct Header <: AbstractTerm
name::String
schema::String
description::String
schema_name::String
model_version::String
end

@as_record struct ASKEModel <: AbstractTerm
header::Header
model::ACSetSpec
semantics::Vector{Semantic}
end

function distro_string(d::Distribution)
@match d begin
StandardUniform => "U(0,1)"
StandardUniform(s) => "U(0,1)"

Check warning on line 25 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L25

Added line #L25 was not covered by tests
Uniform(min, max) => "U($min,$max)"
StandardNormal => "N(0,1)"
StandardNormal(s) => "N(0,1)"

Check warning on line 27 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L27

Added line #L27 was not covered by tests
Normal(mu, var) => "N($mu,$var)"
PointMass(value) => "δ($value)"
end
Expand Down Expand Up @@ -130,10 +52,10 @@
end
padlines(s::String, n=2) = join(padlines(split(s, "\n"), n), "\n")

function amr_to_string(amr)
function amr_to_string(amr)

Check warning on line 55 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L55

Added line #L55 was not covered by tests
let ! = amr_to_string
@match amr begin
s::String => s
@match amr begin
s::String => s

Check warning on line 58 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L57-L58

Added lines #L57 - L58 were not covered by tests
Math(s) => !s
Presentation(s) => "<mathml> $s </mathml>"
u::Unit => !u.expression
Expand All @@ -142,9 +64,9 @@
Rate(t, f) => "$t::Rate = $(f.expression)"
Initial(t, f) => "$t::Initial = $(f.expression)"
Observable(id, n, states, f) => "# $n\n$id::Observable = $(f.expression)($states)\n"
Header(name, s, d, sn, mv) => "\"\"\"\nASKE Model Representation: $name$mv :: $sn \n $s\n\n$d\n\"\"\""
Header(id, name, s, d, sn, mv) => "\"\"\"\nASKE Model Representation: $name$mv :: $sn \n $s\n\n$d\n\"\"\""

Check warning on line 67 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L67

Added line #L67 was not covered by tests
Parameter(t, n, d, u, v, dist) => "\n# $n-- $d\n$t::Parameter{$(!u)} = $v ~ $(!dist)\n"
m::ACSetSpec => "Model = begin\n$(padlines(sprint(show, m),2))\nend"
m::amr.ACSetSpec => "Model = begin\n$(padlines(sprint(show, m),2))\nend"

Check warning on line 69 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L69

Added line #L69 was not covered by tests
ODEList(l) => "ODE_Equations = begin\n" * padlines(join(map(!, l), "\n")) * "\nend"
ODERecord(rts, init, para, time) => join(vcat(["ODE_Record = begin\n"], !rts , !init, !para, [!time, "end"]), "\n")
vs::Vector{Pair} => map(vs) do v; "$(v[1]) => $(v[2])," end |> x-> join(x, "\n")
Expand All @@ -156,7 +78,7 @@
end
end
end

#=
block(exprs) = begin
q = :(begin

Expand All @@ -167,6 +89,7 @@

extract_acsetspec(s::String) = join(split(s, " ")[2:end], " ") |> Meta.parse


function amr_to_expr(amr)
let ! = amr_to_expr
@match amr begin
Expand Down Expand Up @@ -460,4 +383,5 @@
end
ASKEModel(elts[2][1], elts[2][2], [elts[4], elts[6]])
end
=#
end # module end
6 changes: 6 additions & 0 deletions src/composite_models.it
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@sum CompositeModel begin
OpenModel(model::decapodes.ASKEMDecaExpr, interface::Vector{Symbol})
OpenDecapode(model::decapodes.ASKEMDecapode, interface::Vector{Symbol})
CompositeModelExpr(header::amr.Header, composition_pattern::uwd.UWDExpr, components::Vector{CompositeModel})
end
Loading
Loading