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 23 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"
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
150 changes: 38 additions & 112 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,104 +14,28 @@
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

using .amr

nounit = Unit("", nomath)

@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)
function distro_string(d::amr.Distribution)

Check warning on line 23 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L23

Added line #L23 was not covered by tests
@match d begin
StandardUniform => "U(0,1)"
Uniform(min, max) => "U($min,$max)"
StandardNormal => "N(0,1)"
Normal(mu, var) => "N($mu,$var)"
PointMass(value) => "δ($value)"
amr.StandardUniform(s) => "U(0,1)"
amr.Uniform(min, max) => "U($min,$max)"
amr.StandardNormal(s) => "N(0,1)"
amr.Normal(mu, var) => "N($mu,$var)"
amr.PointMass(value) => "δ($value)"

Check warning on line 29 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L25-L29

Added lines #L25 - L29 were not covered by tests
end
end

function distro_expr(d::Distribution)
function distro_expr(d::amr.Distribution)

Check warning on line 33 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L33

Added line #L33 was not covered by tests
return Base.Meta.parse(distro_string(d))
end

#=

function note_string(n::Note)
@match n begin
Name(n) => "Name($n)"
Expand All @@ -129,34 +53,34 @@
" "^n * s
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 57 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L57

Added line #L57 was not covered by tests
let ! = amr_to_string
@match amr begin
s::String => s
Math(s) => !s
Presentation(s) => "<mathml> $s </mathml>"
u::Unit => !u.expression
d::Distribution => distro_string(d)
Time(id, u) => "$id::Time{$(!u)}\n"
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\"\"\""
Parameter(t, n, d, u, v, dist) => "\n# $n-- $d\n$t::Parameter{$(!u)} = $v ~ $(!dist)\n"
@match amr begin
s::String => s
amr.Math(s) => !s
amr.Presentation(s) => "<mathml> $s </mathml>"
u::amr.Unit => !u.expression
d::amr.Distribution => distro_string(d)
amr.Time(id, u) => "$id::Time{$(!u)}\n"
amr.Rate(t, f) => "$t::Rate = $(f.expression)"
amr.Initial(t, f) => "$t::Initial = $(f.expression)"
amr.Observable(id, n, states, f) => "# $n\n$id::Observable = $(f.expression)($states)\n"
amr.Header(id, name, s, d, sn, mv) => "\"\"\"\nASKE Model Representation: $name$mv :: $sn \n $s\n\n$d\n\"\"\""
amr.Parameter(t, n, d, u, v, dist) => "\n# $n-- $d\n$t::Parameter{$(!u)} = $v ~ $(!dist)\n"

Check warning on line 70 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L59-L70

Added lines #L59 - L70 were not covered by tests
m::ACSetSpec => "Model = begin\n$(padlines(sprint(show, m),2))\nend"
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")
vs::Vector{Semantic} => join(map(!, vs), "\n\n")
amr.ODEList(l) => "ODE_Equations = begin\n" * padlines(join(map(!, l), "\n")) * "\nend"
amr.ODERecord(rts, init, para, time) => join(vcat(["ODE_Record = begin\n"], !rts , !init, !para, [!time, "end"]), "\n")
vs::Vector{amr.Pair} => map(vs) do v; "$(v[1]) => $(v[2])," end |> x-> join(x, "\n")
vs::Vector{amr.Semantic} => join(map(!, vs), "\n\n")

Check warning on line 75 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L72-L75

Added lines #L72 - L75 were not covered by tests
xs::Vector => map(!, xs)
Typing(system, map) => "Typing = begin\n$(padlines(!system, 2))\nTypeMap = [\n$(padlines(!map, 2))]\nend"
ASKEModel(h, m, s) => "$(!h)\n$(!m)\n\n$(!s)"
Annotation(e,t,n) => "Annotation = $(String(e)),$(String(t)): $(note_string(n))"
# amr.Typing(system, map) => "Typing = begin\n$(padlines(!system, 2))\nTypeMap = [\n$(padlines(!map, 2))]\nend"
# amr.ASKEModel(h, m, s) => "$(!h)\n$(!m)\n\n$(!s)"
amr.Annotation(e,t,n) => "Annotation = $(String(e)),$(String(t)): $(note_string(n))"

Check warning on line 79 in src/amr.jl

View check run for this annotation

Codecov / codecov/patch

src/amr.jl#L79

Added line #L79 was not covered by tests
end
end
end

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

Expand All @@ -167,6 +91,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 +385,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