Skip to content

Commit

Permalink
feat(biosimulations): return URLs for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayankur31 committed Jul 4, 2024
1 parent a4f37bb commit 81abeea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
39 changes: 29 additions & 10 deletions pyneuroml/biosimulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def submit_simulation_archive(
archive_file: str,
sim_dict: typing.Dict[str, typing.Union[int, str, typing.List[str]]] = {},
dry_run: bool = False,
) -> object:
) -> typing.Dict[str, typing.Union[str, object]]:
"""Submit an OMEX archive to biosimulations using the provided simulation run dictionary
.. versionadded:: 1.2.10
Expand Down Expand Up @@ -203,7 +203,12 @@ def submit_simulation_archive(
https://api.biosimulations.org/#/Simulations/SimulationRunController_createRun
:type sim_dict: dict
:returns: the requests.post response object, or True if dry_run
:returns: dictionary with keys "response", "download", "logs", "view" that
contain the response object and download, logs, and view URLs
If a dry run, response is True and the URLs are all None
:rtype: dict
"""
api_url = f"{biosimulations_api_url}/runs"
Expand All @@ -230,6 +235,8 @@ def submit_simulation_archive(
logger.info(f"multipart encoded data is {m}")
logger.info(f"with content type: {m.content_type}")

resdict = {}

if dry_run is False:
logger.info("Submitting archive to biosimulations")
response = requests.post(
Expand All @@ -242,17 +249,29 @@ def submit_simulation_archive(
print(
f"Submitted {archive_file} successfully with id: {serv_response['id']}"
)
print(f"View: {biosimulations_api_url}/runs/{serv_response['id']}")
download_url = f'{biosimulations_api_url}/results/{serv_response["id"]}/download'
print(
f"Downloads: {download_url}"
)
print(
f"Logs: {biosimulations_api_url}/logs/{serv_response['id']}?includeOutput=true"

log_url = f"{biosimulations_api_url}/logs/{serv_response['id']}?includeOutput=true"
view_url = f"{biosimulations_api_url}/runs/{serv_response['id']}"
download_url = (
f'{biosimulations_api_url}/results/{serv_response["id"]}/download'
)

print(f"View: {view_url}")
print(f"Downloads: {download_url}")
print(f"Logs: {log_url}")

resdict["response"] = response
resdict["view"] = view_url
resdict["download"] = download_url
resdict["logs"] = log_url
else:
response = True
print("Dry run, not submitting")
print(f"Simulation dictionary: {sim_dict}")

return download_url, response
resdict["response"] = response
resdict["view"] = None
resdict["download"] = None
resdict["logs"] = None

return resdict
3 changes: 2 additions & 1 deletion tests/test_biosimulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def test_submit_simulation(self):
"maxTime": "20",
}

response = submit_simulation(
resdict = submit_simulation(
"LEMS_NML2_Ex5_DetCell.xml", sim_dict=sim_dict, dry_run=dry_run
)
response = resdict["response"]
os.chdir(cwd)

if dry_run:
Expand Down

0 comments on commit 81abeea

Please sign in to comment.