Skip to content

Commit b3d7fa3

Browse files
authored
📝 Adds rabbit ss1d example script for public-api [skip actions] (ITISFoundation#3138)
1 parent 326d0e9 commit b3d7fa3

File tree

5 files changed

+271
-0
lines changed

5 files changed

+271
-0
lines changed

tests/public-api/examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
*.json
33
*.txt
44
*.ipynb
5+
# input files
6+
!data_rabbit_cardiac/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.37502380000000e-03 9.87089040000000e-01 9.91792330000000e-01 7.01839599059895e-06 1.00067670000000e+00 2.71686070000000e-02 1.61672490000000e-02 4.30233143427199e-03 7.80717071021313e-01 4.30070614007387e-03 9.91776471924169e-01 1.92953960206578e-01 6.03487435980430e-02 7.83830949712806e-01 6.87394160908516e-07 1.89572432945224e-07 2.72749907930016e+00 5.94139243736699e-01 1.01817556868506e-02 1.07772490680837e-01 1.53675089037119e-02 2.53281010000000e-04 1.45194984664938e-03 1.38049879142935e-01 2.42453028953050e-03 7.94665117780574e-03 1.15032206558552e-02 7.72148958403062e-02 1.29512937945466e-01 1.22533949113428e+00 5.41856748595056e-01 5.66263070928663e+00 5.65803488782485e+00 5.65793960414529e+00 1.35000000000000e+02 1.87973841710593e-04 1.24175755576104e-04 9.80439326045149e-05 -8.46709654219819e+01 4.76724435751784e-01 0.00000000000000e+00 0.00000000000000e+00 2.54396524740325e+04 -1.61779918341570e+04 -1.89056393255094e+05 1.79868522042596e+05 2.63837800000000e-01 8.96327497908432e-02 8.42492982261963e-03 1.21975521245901e-03 3.26626538090676e-01 9.83564517952387e-03 1.12758648482790e-01 1.06074803099061e-02 1.54342185242217e-03 4.13351671573873e-01 1.23740090409898e-02 1.82464940000000e-08 2.17002140000000e-11 8.26062916474434e-01 2.24698596325533e-05 1.46097101414056e-02 1.08508307672484e-01 4.09476672435635e-05 5.07533657008860e-02 8.28518788627629e-01 2.34971524306373e-05 1.44586344628127e-02 1.07405533939698e-01 3.99761539610029e-05 4.95264603326507e-02 8.79587288126774e-01 2.27195074764805e-05 3.59555538012108e-03 2.67047140344325e-02 7.32547547699722e-05 9.00141866610291e-02 8.85784874410360e-01 2.31126063678609e-05 3.48258885399952e-03 2.58703452502185e-02 6.88339462452406e-05 8.47461860899517e-02 1.61197296381461e-06 2.08577373084540e-04 1.19065445556838e-01 7.58655435631373e-01 6.04551404486629e-02 9.48755677017729e-03 1.66090987262331e-05 0.00000000000000e+00 0.00000000000000e+00 2.39524978782952e-02 6.41644384969010e-11 1.19820407631612e-04 1.88032327044201e-05 3.28971137723882e-08 4.32110272330849e-16 4.14600638669982e-16 2.36953168780722e-13 1.50956358017391e-12 2.80183257033658e-02 8.58915687332272e-08 1.35149200867794e-08 2.45339571906417e-11 4.36074558006248e-08 0.00000000000000e+00 1.62668363490110e-24 6.41053442026113e-20 1.00686660060463e-20 1.79607163383628e-23 0.00000000000000e+00 0.00000000000000e+00 0.00000000000000e+00 0.00000000000000e+00 1.49843392018885e-304 0.00000000000000e+00 0.00000000000000e+00 0.00000000000000e+00 0.00000000000000e+00 0.00000000000000e+00 0.00000000000000e+00 4.64736956982462e-308 0.00000000000000e+00 0.00000000000000e+00 3.10083021551703e+02 1.52889432592164e+01 2.17165991156356e-02 0.00000000000000e+00 0.00000000000000e+00 0.00000000000000e+00 6.25423662824822e-01 1.70392706443729e-01 2.56713533507026e-04 1.42012427431816e-07 4.64851570532643e-08 3.24347125705691e-05 8.51926937302723e-04 6.95689012955649e-03 3.60966328077369e+00 5.43669998029717e-02 1.30758805639508e-04 1.35952373082443e-08 4.02034169944412e+00 2.54454801911598e+00 9.22860104152380e-05 2.66162821507126e-05 2.05179346147960e-05 1.87751969476251e-10 1.92476135791525e-15 3.85036350012499e-13 7.50785280086099e-04 3.49663333278284e-06 8.33961549884873e-06 7.89029758893487e-05 5.47294143136563e-02 1.04661405029684e-04 2.44123287931858e-09 5.01983277671203e+00 5.44221357647924e-01 1.22873074199756e-05 2.11059375521054e-05 2.00550698354832e-07 3.42362146247288e-15 3.53881975068991e-20 2.51868615353371e-17 7.87540959809223e-05 3.68753352895029e-07 1.75011101599083e-07 1.25079095005594e-07 1.64543925700837e+01 1.09157042751614e+01 2.97357231348733e+02 7.31005853939613e+01 2.83951986455465e-01 2.40580245812117e-07 0.00000000000000e+00 2.47551246368891e-02 3.82712905888321e+00 2.76260657536887e-02 1.29022777091755e-15 3.73934129310940e-04 5.74188223353930e-02 6.54316118275670e-04 5.80191388872594e-02 5.20107532057645e-02 0.00000000000000e+00 4.15919308703744e-02 3.60000000000000e-02 0.00000000000000e+00 4.86632231379200e-01 7.16671468785635e-02 8.27172793207883e-03 3.17804779433581e-03 2.78595406619341e-01 8.07506891729879e-03 9.14572121457175e-06 8.81934076803921e-01 6.95895393319336e-04 8.21087151601780e-04 3.29852404512875e-03 2.19146094413653e-01 1.53192920196010e-03 1.53192920195145e-03 1.83611114431063e-03 4.05926843054623e-03 0.00000000000000e+00
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
"inputs": {
3+
"Na": {
4+
"displayOrder": 1,
5+
"label": "Na blocker",
6+
"description": "Na blocker drug concentration",
7+
"type": "integer",
8+
"defaultValue": "0"
9+
},
10+
"GKr": {
11+
"displayOrder": 2,
12+
"label": "GKr ratio",
13+
"description": "GKr ratio",
14+
"type": "integer",
15+
"defaultValue": 1
16+
},
17+
"TotalSimulationTime": {
18+
"displayOrder": 3,
19+
"label": "Total simulation time",
20+
"description": "Total simulation time",
21+
"type": "integer",
22+
"defaultValue": 300
23+
},
24+
"TargetHeartRatePhase1": {
25+
"displayOrder": 4,
26+
"label": "Target heart rate for phase 1",
27+
"description": "Target heart rate for phase 1",
28+
"type": "integer",
29+
"defaultValue": 60
30+
},
31+
"TargetHeartRatePhase2": {
32+
"displayOrder": 5,
33+
"label": "Target heart rate for phase 2",
34+
"description": "Target heart rate for phase 2",
35+
"type": "integer",
36+
"defaultValue": 150
37+
},
38+
"TargetHeartRatePhase3": {
39+
"displayOrder": 6,
40+
"label": "Target heart rate for phase 3",
41+
"description": "Target heart rate for phase 3",
42+
"type": "integer",
43+
"defaultValue": 60
44+
},
45+
"cAMKII": {
46+
"displayOrder": 7,
47+
"label": "cAMKII activity levels",
48+
"description": "cAMKII activity levels (expression = 'WT', 'OE', or 'KO'",
49+
"type": "string",
50+
"defaultValue": "WT"
51+
},
52+
"tissue_size_tw": {
53+
"displayOrder": 8,
54+
"label": "Tissue width (# of cells)",
55+
"description": "Tissue width (# of cells)",
56+
"type": "integer",
57+
"defaultValue": "165"
58+
},
59+
"tissue_size_tl": {
60+
"displayOrder": 9,
61+
"label": "Tissue length (# of cells)",
62+
"description": "Tissue length (# of cells)",
63+
"type": "integer",
64+
"defaultValue": "165"
65+
},
66+
"Homogeneity": {
67+
"displayOrder": 10,
68+
"label": "Homogeneity",
69+
"description": "Homogeneity (expression = 'homogeneous', or 'heterogeneous'",
70+
"type": "string",
71+
"defaultValue": "homogeneous"
72+
},
73+
"initialWTStates": {
74+
"displayOrder": 11,
75+
"label": "Initial WT states",
76+
"description": "Initial WT states",
77+
"type": "data:text/plain",
78+
"fileToKeyMap": {
79+
"initial_WTstates.txt": "initialWTStates"
80+
}
81+
},
82+
"num_threads": {
83+
"displayOrder": 12,
84+
"label": "# threads",
85+
"description": "Desired number of threads",
86+
"type": "integer",
87+
"defaultValue": 2
88+
}
89+
},
90+
"outputs": {
91+
"output_1": {
92+
"displayOrder": 1,
93+
"label": "ECGs",
94+
"description": "ECGs",
95+
"type": "data:text/plain",
96+
"fileToKeyMap": {
97+
"ECGs.txt": "output_1"
98+
}
99+
},
100+
"output_2": {
101+
"displayOrder": 3,
102+
"label": "APs",
103+
"description": "APs",
104+
"type": "data:text/plain",
105+
"fileToKeyMap": {
106+
"ap_1D.txt": "output_2"
107+
}
108+
},
109+
"output_3": {
110+
"displayOrder": 4,
111+
"label": "CAIs",
112+
"description": "CAIs",
113+
"type": "data:text/plain",
114+
"fileToKeyMap": {
115+
"cai_1D.txt": "output_3"
116+
}
117+
},
118+
"output_4": {
119+
"displayOrder": 5,
120+
"label": "Input from 1D",
121+
"description": "Model input from 1D to 2D solver",
122+
"type": "data:*/*",
123+
"fileToKeyMap": {
124+
"model_INPUT.from1D": "output_4"
125+
}
126+
}
127+
}
128+
}

tests/public-api/examples/opencor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
$ make install-ci
55
$ make .env
66
7+
8+
Based on example https://github.com/nih-sparc/sparc-api/blob/v1.5.0/app/osparc.py
79
"""
810
import json
911
import os
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
"""
2+
Multi-scale rabbit cardiac electrophysiology models
3+
Rabbit Soltis-Saucerman model with full b-AR signalling (Rabbit SS 1D cardiac)
4+
5+
$ cd examples
6+
$ make install-ci
7+
$ make .env
8+
9+
SEE https://sparc.science/datasets/4?type=dataset
10+
"""
11+
import os
12+
import sys
13+
import time
14+
from pathlib import Path
15+
from time import sleep
16+
from typing import Optional
17+
18+
import osparc
19+
from dotenv import load_dotenv
20+
from osparc.models import File, JobStatus
21+
22+
assert osparc.__version__ == "0.4.3"
23+
24+
current_dir = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
25+
data_dir = current_dir / "data_rabbit_cardiac"
26+
27+
load_dotenv()
28+
cfg = osparc.Configuration(
29+
host=os.environ.get("OSPARC_API_URL", "http://127.0.0.1:8006"),
30+
username=os.environ["OSPARC_API_KEY"],
31+
password=os.environ["OSPARC_API_SECRET"],
32+
)
33+
print("Entrypoint", cfg.host)
34+
35+
36+
with osparc.ApiClient(cfg) as api_client:
37+
# Upload init states file.
38+
39+
files_api = osparc.FilesApi(api_client)
40+
initial_wtstates_file = files_api.upload_file(
41+
str(data_dir / "initial_WTstates.txt")
42+
)
43+
44+
# Create our simulation.
45+
46+
solvers_api = osparc.SolversApi(api_client)
47+
48+
solver = solvers_api.get_solver_release(
49+
"simcore/services/comp/rabbit-ss-1d-cardiac-model", "1.0.0"
50+
)
51+
52+
# SEE data_rabbit_cardiac/ss1d_meta.json::inputs
53+
job = solvers_api.create_job(
54+
solver.id,
55+
solver.version,
56+
osparc.JobInputs(
57+
{
58+
"Na": 0,
59+
"GKr": 1,
60+
"TotalSimulationTime": 50,
61+
"TargetHeartRatePhase1": 60,
62+
"TargetHeartRatePhase2": 150,
63+
"TargetHeartRatePhase3": 60,
64+
"cAMKII": "WT",
65+
"tissue_size_tw": 165,
66+
"tissue_size_tl": 165,
67+
"Homogeneity": "homogeneous",
68+
"num_threads": 4,
69+
"initialWTStates": initial_wtstates_file,
70+
}
71+
),
72+
)
73+
print("Job created", job)
74+
75+
# Start our simulation.
76+
status = solvers_api.start_job(solver.id, solver.version, job.id)
77+
start_t = time.perf_counter()
78+
79+
# Check the status of our simulation until it has completed.
80+
while True:
81+
status = solvers_api.inspect_job(solver.id, solver.version, job.id)
82+
83+
print(
84+
f">>> Progress: {status.progress}% ",
85+
f"[elapsed:{time.perf_counter() - start_t:4.2f}s]...",
86+
flush=True,
87+
)
88+
89+
if status.progress == 100:
90+
break
91+
92+
sleep(1)
93+
94+
# Retrieve our simulation outputs.
95+
96+
print("---------------------------------------")
97+
last_status: JobStatus = solvers_api.inspect_job(solver.id, solver.version, job.id)
98+
print(">>> What is the status?", last_status)
99+
100+
outputs = solvers_api.get_job_outputs(solver.id, solver.version, job.id)
101+
102+
# SEE data_rabbit_cardiac/ss1d_meta.json::outputs
103+
for output_name, result in outputs.results.items():
104+
print(f">>> {output_name} = {result}")
105+
106+
# Retrieve our simulation results.
107+
108+
print("---------------------------------------")
109+
result: Optional[File]
110+
111+
for output_name, result in outputs.results.items():
112+
if result is None:
113+
print(
114+
"Can't retrieve our simulation results {output_name}...?!",
115+
"Failed ?",
116+
last_status.state,
117+
"Finished ?",
118+
last_status.progress == 100 or not last_status.stopped_at,
119+
)
120+
else:
121+
122+
# Print out the id of our simulation results file (?).
123+
124+
print("---------------------------------------")
125+
print(">>> ", result.id)
126+
127+
# Download our simulation results file (?).
128+
129+
download_path: str = files_api.download_file(result.id)
130+
print("Downloaded to", download_path)
131+
print("Content-Type: ", result.content_type)
132+
if result.content_type == "text/plain":
133+
print("Result:", Path(download_path).read_text()[:100])
134+
print("Status: ", Path(download_path).stat())
135+
136+
# List all the files that are available.
137+
print("---------------------------------------")
138+
print(files_api.list_files())

0 commit comments

Comments
 (0)