-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 Adds rabbit ss1d example script for public-api [skip actions] (#3138)
- Loading branch information
Showing
5 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
*.json | ||
*.txt | ||
*.ipynb | ||
# input files | ||
!data_rabbit_cardiac/ |
1 change: 1 addition & 0 deletions
1
tests/public-api/examples/data_rabbit_cardiac/initial_WTstates.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 |
128 changes: 128 additions & 0 deletions
128
tests/public-api/examples/data_rabbit_cardiac/ss1d_meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
{ | ||
"inputs": { | ||
"Na": { | ||
"displayOrder": 1, | ||
"label": "Na blocker", | ||
"description": "Na blocker drug concentration", | ||
"type": "integer", | ||
"defaultValue": "0" | ||
}, | ||
"GKr": { | ||
"displayOrder": 2, | ||
"label": "GKr ratio", | ||
"description": "GKr ratio", | ||
"type": "integer", | ||
"defaultValue": 1 | ||
}, | ||
"TotalSimulationTime": { | ||
"displayOrder": 3, | ||
"label": "Total simulation time", | ||
"description": "Total simulation time", | ||
"type": "integer", | ||
"defaultValue": 300 | ||
}, | ||
"TargetHeartRatePhase1": { | ||
"displayOrder": 4, | ||
"label": "Target heart rate for phase 1", | ||
"description": "Target heart rate for phase 1", | ||
"type": "integer", | ||
"defaultValue": 60 | ||
}, | ||
"TargetHeartRatePhase2": { | ||
"displayOrder": 5, | ||
"label": "Target heart rate for phase 2", | ||
"description": "Target heart rate for phase 2", | ||
"type": "integer", | ||
"defaultValue": 150 | ||
}, | ||
"TargetHeartRatePhase3": { | ||
"displayOrder": 6, | ||
"label": "Target heart rate for phase 3", | ||
"description": "Target heart rate for phase 3", | ||
"type": "integer", | ||
"defaultValue": 60 | ||
}, | ||
"cAMKII": { | ||
"displayOrder": 7, | ||
"label": "cAMKII activity levels", | ||
"description": "cAMKII activity levels (expression = 'WT', 'OE', or 'KO'", | ||
"type": "string", | ||
"defaultValue": "WT" | ||
}, | ||
"tissue_size_tw": { | ||
"displayOrder": 8, | ||
"label": "Tissue width (# of cells)", | ||
"description": "Tissue width (# of cells)", | ||
"type": "integer", | ||
"defaultValue": "165" | ||
}, | ||
"tissue_size_tl": { | ||
"displayOrder": 9, | ||
"label": "Tissue length (# of cells)", | ||
"description": "Tissue length (# of cells)", | ||
"type": "integer", | ||
"defaultValue": "165" | ||
}, | ||
"Homogeneity": { | ||
"displayOrder": 10, | ||
"label": "Homogeneity", | ||
"description": "Homogeneity (expression = 'homogeneous', or 'heterogeneous'", | ||
"type": "string", | ||
"defaultValue": "homogeneous" | ||
}, | ||
"initialWTStates": { | ||
"displayOrder": 11, | ||
"label": "Initial WT states", | ||
"description": "Initial WT states", | ||
"type": "data:text/plain", | ||
"fileToKeyMap": { | ||
"initial_WTstates.txt": "initialWTStates" | ||
} | ||
}, | ||
"num_threads": { | ||
"displayOrder": 12, | ||
"label": "# threads", | ||
"description": "Desired number of threads", | ||
"type": "integer", | ||
"defaultValue": 2 | ||
} | ||
}, | ||
"outputs": { | ||
"output_1": { | ||
"displayOrder": 1, | ||
"label": "ECGs", | ||
"description": "ECGs", | ||
"type": "data:text/plain", | ||
"fileToKeyMap": { | ||
"ECGs.txt": "output_1" | ||
} | ||
}, | ||
"output_2": { | ||
"displayOrder": 3, | ||
"label": "APs", | ||
"description": "APs", | ||
"type": "data:text/plain", | ||
"fileToKeyMap": { | ||
"ap_1D.txt": "output_2" | ||
} | ||
}, | ||
"output_3": { | ||
"displayOrder": 4, | ||
"label": "CAIs", | ||
"description": "CAIs", | ||
"type": "data:text/plain", | ||
"fileToKeyMap": { | ||
"cai_1D.txt": "output_3" | ||
} | ||
}, | ||
"output_4": { | ||
"displayOrder": 5, | ||
"label": "Input from 1D", | ||
"description": "Model input from 1D to 2D solver", | ||
"type": "data:*/*", | ||
"fileToKeyMap": { | ||
"model_INPUT.from1D": "output_4" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
""" | ||
Multi-scale rabbit cardiac electrophysiology models | ||
Rabbit Soltis-Saucerman model with full b-AR signalling (Rabbit SS 1D cardiac) | ||
$ cd examples | ||
$ make install-ci | ||
$ make .env | ||
SEE https://sparc.science/datasets/4?type=dataset | ||
""" | ||
import os | ||
import sys | ||
import time | ||
from pathlib import Path | ||
from time import sleep | ||
from typing import Optional | ||
|
||
import osparc | ||
from dotenv import load_dotenv | ||
from osparc.models import File, JobStatus | ||
|
||
assert osparc.__version__ == "0.4.3" | ||
|
||
current_dir = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent | ||
data_dir = current_dir / "data_rabbit_cardiac" | ||
|
||
load_dotenv() | ||
cfg = osparc.Configuration( | ||
host=os.environ.get("OSPARC_API_URL", "http://127.0.0.1:8006"), | ||
username=os.environ["OSPARC_API_KEY"], | ||
password=os.environ["OSPARC_API_SECRET"], | ||
) | ||
print("Entrypoint", cfg.host) | ||
|
||
|
||
with osparc.ApiClient(cfg) as api_client: | ||
# Upload init states file. | ||
|
||
files_api = osparc.FilesApi(api_client) | ||
initial_wtstates_file = files_api.upload_file( | ||
str(data_dir / "initial_WTstates.txt") | ||
) | ||
|
||
# Create our simulation. | ||
|
||
solvers_api = osparc.SolversApi(api_client) | ||
|
||
solver = solvers_api.get_solver_release( | ||
"simcore/services/comp/rabbit-ss-1d-cardiac-model", "1.0.0" | ||
) | ||
|
||
# SEE data_rabbit_cardiac/ss1d_meta.json::inputs | ||
job = solvers_api.create_job( | ||
solver.id, | ||
solver.version, | ||
osparc.JobInputs( | ||
{ | ||
"Na": 0, | ||
"GKr": 1, | ||
"TotalSimulationTime": 50, | ||
"TargetHeartRatePhase1": 60, | ||
"TargetHeartRatePhase2": 150, | ||
"TargetHeartRatePhase3": 60, | ||
"cAMKII": "WT", | ||
"tissue_size_tw": 165, | ||
"tissue_size_tl": 165, | ||
"Homogeneity": "homogeneous", | ||
"num_threads": 4, | ||
"initialWTStates": initial_wtstates_file, | ||
} | ||
), | ||
) | ||
print("Job created", job) | ||
|
||
# Start our simulation. | ||
status = solvers_api.start_job(solver.id, solver.version, job.id) | ||
start_t = time.perf_counter() | ||
|
||
# Check the status of our simulation until it has completed. | ||
while True: | ||
status = solvers_api.inspect_job(solver.id, solver.version, job.id) | ||
|
||
print( | ||
f">>> Progress: {status.progress}% ", | ||
f"[elapsed:{time.perf_counter() - start_t:4.2f}s]...", | ||
flush=True, | ||
) | ||
|
||
if status.progress == 100: | ||
break | ||
|
||
sleep(1) | ||
|
||
# Retrieve our simulation outputs. | ||
|
||
print("---------------------------------------") | ||
last_status: JobStatus = solvers_api.inspect_job(solver.id, solver.version, job.id) | ||
print(">>> What is the status?", last_status) | ||
|
||
outputs = solvers_api.get_job_outputs(solver.id, solver.version, job.id) | ||
|
||
# SEE data_rabbit_cardiac/ss1d_meta.json::outputs | ||
for output_name, result in outputs.results.items(): | ||
print(f">>> {output_name} = {result}") | ||
|
||
# Retrieve our simulation results. | ||
|
||
print("---------------------------------------") | ||
result: Optional[File] | ||
|
||
for output_name, result in outputs.results.items(): | ||
if result is None: | ||
print( | ||
"Can't retrieve our simulation results {output_name}...?!", | ||
"Failed ?", | ||
last_status.state, | ||
"Finished ?", | ||
last_status.progress == 100 or not last_status.stopped_at, | ||
) | ||
else: | ||
|
||
# Print out the id of our simulation results file (?). | ||
|
||
print("---------------------------------------") | ||
print(">>> ", result.id) | ||
|
||
# Download our simulation results file (?). | ||
|
||
download_path: str = files_api.download_file(result.id) | ||
print("Downloaded to", download_path) | ||
print("Content-Type: ", result.content_type) | ||
if result.content_type == "text/plain": | ||
print("Result:", Path(download_path).read_text()[:100]) | ||
print("Status: ", Path(download_path).stat()) | ||
|
||
# List all the files that are available. | ||
print("---------------------------------------") | ||
print(files_api.list_files()) |