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

Add Schemas for Stock and Flow #35

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/acsets/acsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ def __init__(
ob: create_model(
ob.name,
**{
prop.name: (Union[self.valtype(prop), None], None)
prop.name: (Union[self.valtype(prop), None], Field(title=ob.title, description=ob.description))
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it the case that all elements will always be lists? If that's the case, we can use this line to introduce default empty lists.

for prop in self.props_outof(ob)
},
)
for ob in obs
}
self.ob_models = ob_models
self.model = create_model(
self.name, **{ob.name: (list[ob_models[ob]], ...) for ob in self.obs} # type: ignore
self.name, **{ob.name: (list[ob_models[ob]], Field(default_factory=list)) for ob in self.obs} # type: ignore
)

def valtype(self, prop: Property):
Expand Down
184 changes: 184 additions & 0 deletions src/acsets/schemas/catlab/StockFlow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
{
"version": {
"ACSets": "0.0.0",
"ACSetSchema": "0.0.1",
"Catlab": "0.0.0"
},
"Ob": [
{
"title": "Stocks",
"description": "A variable in the model",
"name": "S"
},
{
"title": "Sum Aux",
"description": "Sum Auxiliary Variable",
"name": "SV"
},
{
"title": "Linkage",
"description": null,
"name": "LS"
},
{
"title": "Flow",
"description": "A flow between stocks",
"name": "F"
},
{
"title": "Input",
"description": "The input arcs",
"name": "I"
},
{
"title": "Output",
"description": "The output arcs",
"name": "O"
},
{
"title": "Variable?",
"description": null,
"name": "V"
},
{
"title": "Linkage Variable?",
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are some question marks here we probably want to address

"description": null,
"name": "LV"
},
{
"title": "Linkage Sum Variables?",
"description": null,
"name": "LSV"
}
],
"Hom": [
{
"title": "LS to stock",
"description": null,
"name": "lss",
"codom": "S",
"dom": "LS"
},
{
"title": "LS to SV",
"description": null,
"name": "lssv",
"codom": "SV",
"dom": "LS"
},
{
"title": "Input to Function",
"description": null,
"name": "ifn",
"codom": "F",
"dom": "I"
},
{
"title": "Input variable",
"description": null,
"name": "is",
"codom": "S",
"dom": "I"
},
{
"title": "Output of Function",
"description": null,
"name": "ofn",
"codom": "F",
"dom": "O"
},
{
"title": "Output Variable",
"description": null,
"name": "os",
"codom": "S",
"dom": "O"
},
{
"title": "Variable Result of Function",
"description": null,
"name": "fv",
"codom": "V",
"dom": "F"
},
{
"title": "S of V",
"description": null,
"name": "lvs",
"codom": "S",
"dom": "LV"
},
{
"title": "V of LV",
"description": null,
"name": "lvv",
"codom": "V",
"dom": "LV"
},
{
"title": "SV of LSV",
"description": null,
"name": "lsvsv",
"codom": "SV",
"dom": "LSV"
},
{
"title": "V of LSV",
"description": null,
"name": "lsvv",
"codom": "V",
"dom": "LSV"
}
],
"AttrType": [
{
"name": "Name",
"title": "Name of Entity",
"description": null,
"ty": "str"
},
{
"name": "FuncDynam",
"title": "Dynamics Function",
"description": null,
"ty": "str"
}
],
"Attr": [
{
"title": "Stock Name",
"description": null,
"name": "sname",
"codom": "Name",
"dom": "S"
},
{
"title": "SV Name",
"description": null,
"name": "svname",
"codom": "Name",
"dom": "SV"
},
{
"title": "Function Name",
"description": null,
"name": "fname",
"codom": "Name",
"dom": "F"
},
{
"title": "Variable Name",
"description": null,
"name": "vname",
"codom": "Name",
"dom": "V"
},
{
"title": "Dynamics Function of Variable",
"description": null,
"name": "funcDynam",
"codom": "FuncDynam",
"dom": "V"
}
]
}
91 changes: 91 additions & 0 deletions src/acsets/schemas/catlab/StockFlowp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"version": {
"ACSets": "0.0.0",
"ACSetSchema": "0.0.1",
"Catlab": "0.0.0"
},
"Ob": [
{
"name": "Flow",
"title": "Flow",
"description": null
},
{
"name": "Stock",
"title": "Stock",
"description": null
},
{
"name": "Link",
"title": "Link",
"description": null
}
],
"Hom": [
{
"name": "u",
"codom": "Stock",
"dom": "Flow",
"title": "upstream",
"description": null
},
{
"name": "d",
"codom": "Stock",
"dom": "Flow",
"title": "downstream",
"description": null
},
{
"name": "s",
"codom": "Stock",
"dom": "Link",
"title": "source",
"description": null
},
{
"name": "t",
"codom": "Flow",
"dom": "Link",
"title": "target",
"description": null
}
],
"AttrType": [
{
"name": "Name",
"title": "Names",
"description": "Name of an entity in the model.",
"ty": "str"
},
{
"name": "FuncFlow",
"title": "Flow Functions",
"description": "A representation of the flow function. Currently a math expression in string form.",
"ty": "str"
}
],
"Attr": [
{
"title": "Stock Name",
"description": null,
"name": "sname",
"codom": "Name",
"dom": "Stock"
},
{
"title": "Flow Name",
"description": null,
"name": "fname",
"codom": "Name",
"dom": "Flow"
},
{
"title": "Flow Function",
"description": null,
"name": "ϕf",
Copy link

@mattprintz mattprintz Sep 28, 2023

Choose a reason for hiding this comment

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

Are there any potential integration issues with using a less-common unicode character as a JSON key?
I'm also wondering if this might be especially an issue since there are two unicode glyphs for phi, U+03C6 and U+03D5.
While this is definitely the convention in Julia, perhaps for the interchange format it could be something that is potentially more universally accessible such as ffunc or flowfunc?

Copy link
Member Author

Choose a reason for hiding this comment

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

We should test the JSON libraries. This would be a breaking change to StockFlow.jl so let's find an upstream bug before we patch it?

Choose a reason for hiding this comment

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

Ah. I didn't realize that this would be a breaking change in the other library.

According to the JSON spec, it should be fine, and it obviously works in Python and JS, so I'm happy to assume that everything conforms to the spec until proven otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah the SF.jl library already exists and I was trying to get this in to py-acsets with the minimal code change possible. So far we haven't made any other changes to SF.jl.

"codom": "FuncFlow",
"dom": "Flow"
}
]
}
49 changes: 49 additions & 0 deletions src/acsets/schemas/examples/StockFlowp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"Flow": [
{
"_id": 1,
"u": 1,
"d": 2,
"fname": "NewIncidence",
"ϕf": "p.cβ*u.S*u.I/p.N"
},
{
"_id": 2,
"u": 2,
"d": 3,
"fname": "NewRecovery",
"ϕf": "(u.I/p.tr)"
}
],
"Stock": [
{
"_id": 1,
"sname": "S"
},
{
"_id": 2,
"sname": "I"
},
{
"_id": 3,
"sname": "R"
}
],
"Link": [
{
"_id": 1,
"s": 1,
"t": 1
},
{
"_id": 2,
"s": 2,
"t": 1
},
{
"_id": 3,
"s": 2,
"t": 2
}
]
}
Loading
Loading