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

Technical Report MORAE Notebook Demo #47

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# do not archive notebook checkpoints
.ipynb_checkpoints
__pycache__/
.DS_Store
3 changes: 2 additions & 1 deletion end-to-end-rest/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
- "8000:8000" # Change port mapping appropriately before deploying.
# open browser to http://127.0.0.1:8000/docs
environment:
- "SKEMA_RS_ADDESS=http://skema-rs:8080"
- "SKEMA_RS_ADDRESS=http://skema-rs:8080"
- "SKEMA_GRAPH_DB_PROTO=bolt://"
- "SKEMA_GRAPH_DB_PORT=7687"
- "SKEMA_GRAPH_DB_HOST=graphdb"
Expand All @@ -57,6 +57,7 @@ services:
- "SKEMA_RS_PORT=8080"
- "SKEMA_GRAPH_DB_HOST=graphdb"
- "SKEMA_GRAPH_DB_PORT=7687"
- "SKEMA_GRAPH_DB_PROTO=bolt://"

# We currently use Memgraph (in-memory graph database).
graphdb:
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions end-to-end-rest/notebooks/M11-Q6/data/code/code1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a readme for the SIR model in the base test scenario. This contains no code.
20 changes: 20 additions & 0 deletions end-to-end-rest/notebooks/M11-Q6/data/code/code1/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SIR model dynamics definition
def sir(
s: float, i: float, r: float, beta: float, gamma: float, n: float
) -> Tuple[float, float, float]:
"""The SIR model, one time step."""
s_n = (-beta * s * i) + s
i_n = (beta * s * i - gamma * i) + i
r_n = gamma * i + r
scale = n / (s_n + i_n + r_n)
return s_n * scale, i_n * scale, r_n * scale


if __name__ == "main":
# run sir model sample
result = sir(0.99, 0.01, 0, 0.2, 0.1, 1)

print(result)


# 7e475a4c-cf38-44f3-b349-2badeff967e8
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"semantics": {
"ode": {
"parameters": [
{"name": "a"},
{"name": "b"},
{"name": "c"},
{"name": "int_add"},
{"name": "float_add"},
{"name": "str_concat"},
{"name": "list_concat"},
{"name": "int_sub"},
{"name": "float_sub"},
{"name": "int_mult"},
{"name": "float_mult"},
{"name": "str_repeat"},
{"name": "list_repeat"},
{"name": "float_div"},
{"name": "int_floor_div"},
{"name": "int_mod"},
{"name": "int_pow"},
{"name": "float_pow"},
{"name": "int_lshift"},
{"name": "int_rshift"},
{"name": "bit_or"},
{"name": "bit_and"},
{"name": "bit_xor"},
{"name": "eq_int"},
{"name": "eq_str"},
{"name": "eq_list"},
{"name": "neq_int"},
{"name": "neq_str"},
{"name": "neq_list"},
{"name": "gt_int"},
{"name": "gte_int"},
{"name": "lt_int"},
{"name": "lte_int"}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Assignment types
a = 10
b = a
c = a + b

# Primitive addition
int_add = 5 + 3
float_add = 3.14 + 2.71
str_concat = "Hello" + "World"
list_concat = [1, 2, 3] + [4, 5, 6]

# Primitive subtraction
int_sub = 10 - 3
float_sub = 5.5 - 2.2

# Primitive multiplication
int_mult = 4 * 7
float_mult = 2.5 * 3.5
str_repeat = "abc" * 3
list_repeat = [1, 2, 3] * 2

# Primitive division
float_div = 7.5 / 2.5

# Primitive floor division
int_floor_div = 11 // 3

# Primitive modulo
int_mod = 17 % 5

# Primitive exponentiation
int_pow = 2 ** 3
float_pow = 2.0 ** 3

# Primitive left shift
int_lshift = 8 << 2

# Primitive right shift
int_rshift = 32 >> 2

# Primitive bitwise or
bit_or = 5 | 3

# Primitive bitwise and
bit_and = 5 & 3

# Primitive bitwise xor
bit_xor = 5 ^ 3

# Primitive equality
eq_int = 5 == 5
eq_str = "Hello" == "World"
eq_list = [1, 2, 3] == [1, 2, 3]

# Primitive inequality
neq_int = 5 != 3
neq_str = "Hello" != "Hello"
neq_list = [1, 2, 3] != [4, 5, 6]

# Primitive greater than
gt_int = 5 > 3

# Primitive greater than and equal to
gte_int = 5 >= 5

# Primitive less than
lt_int = 3 < 5

# Primitive less than and equal to
lte_int = 5 <= 5

Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"header": {
"name": "mathml model",
"schema": "https://github.com/DARPA-ASKEM/Model-Representations/blob/main/petrinet/petrinet_schema.json",
"schema_name": "PetriNet",
"description": "This is a model from equations",
"model_version": "0.1"
},
"model": {
"states": [
{
"id": "D",
"name": "D"
},
{
"id": "E",
"name": "E"
},
{
"id": "I",
"name": "I"
},
{
"id": "R",
"name": "R"
},
{
"id": "S",
"name": "S"
}
],
"transitions": [
{
"id": "t0",
"input": [
"I",
"S"
],
"output": [
"E",
"I"
]
},
{
"id": "t1",
"input": [
"E"
],
"output": [
"I"
]
},
{
"id": "t2",
"input": [
"I"
],
"output": [
"R"
]
},
{
"id": "t3",
"input": [
"I"
],
"output": [
"D"
]
}
]
},
"semantics": {
"ode": {
"rates": [
{
"target": "t0",
"expression": "N*beta*I*S",
"expression_mathml": "<apply><times/><apply><times/><ci>I</ci><ci>beta</ci><ci>S</ci></apply><ci>N</ci></apply>"
},
{
"target": "t1",
"expression": "sigma*E",
"expression_mathml": "<apply><times/><ci>sigma</ci><ci>E</ci></apply>"
},
{
"target": "t2",
"expression": "gamma*I",
"expression_mathml": "<apply><times/><ci>gamma</ci><ci>I</ci></apply>"
},
{
"target": "t3",
"expression": "delta*I",
"expression_mathml": "<apply><times/><ci>delta</ci><ci>I</ci></apply>"
}
],
"initials": [
{
"target": "S",
"expression": "",
"expression_mathml": ""
},
{
"target": "E",
"expression": "",
"expression_mathml": ""
},
{
"target": "I",
"expression": "",
"expression_mathml": ""
},
{
"target": "R",
"expression": "",
"expression_mathml": ""
},
{
"target": "D",
"expression": "",
"expression_mathml": ""
}
],
"parameters": [
{
"id": "N",
"name": "N"
},
{
"id": "beta",
"name": "beta"
},
{
"id": "delta",
"name": "delta"
},
{
"id": "gamma",
"name": "gamma"
},
{
"id": "sigma",
"name": "sigma"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

def seird_model(y, t, N, beta, sigma, gamma, delta):
S, E, I, R, D = y
dSdt = -beta * S * I / N
dEdt = beta * S * I / N - sigma * E
dIdt = sigma * E - gamma * I - delta * I
dRdt = gamma * I
dDdt = delta * I
return dSdt, dEdt, dIdt, dRdt, dDdt

N = 1000
beta = 0.2
sigma = 0.1
gamma = 0.05
delta = 0.01
y0 = N-1, 1, 0, 0, 0

t = np.linspace(0, 100, 1000)

result = odeint(seird_model, y0, t, args=(N, beta, sigma, gamma, delta))
S, E, I, R, D = result.T

plt.figure(figsize=(10,6))
plt.plot(t, S, 'b', label='Susceptible')
plt.plot(t, E, 'y', label='Exposed')
plt.plot(t, I, 'r', label='Infected')
plt.plot(t, R, 'g', label='Recovered')
plt.plot(t, D, 'k', label='Dead')
plt.xlabel('Time')
plt.ylabel('Population')
plt.legend()
plt.grid(True)
plt.show()
Loading