Skip to content

Commit

Permalink
fix: update sbml method
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Aug 2, 2024
1 parent c1dddea commit dd8e046
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 37 deletions.
17 changes: 9 additions & 8 deletions bio_check/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def verify_sbml(
endpoint = self._format_endpoint('verify-sbml')

# TODO: fix and remove this
raise NotImplementedError("Submission of jobs with a SBML file is currently under development.")
# raise NotImplementedError("Submission of jobs with a SBML file is currently under development.")

# configure params
_id = comparison_id or "bio_check-request-" + str(uuid4())
Expand All @@ -132,28 +132,29 @@ def verify_sbml(
simulators = ["copasi", "tellurium"]

# create encoder fields
encoder_fields = {
'uploaded_file': sbml_fp,
encoder_fields = {'uploaded_file': sbml_fp}

query_params = {
'simulators': ','.join(simulators),
'include_outputs': str(include_outputs).lower(),
'comparison_id': _id,
'duration': str(duration),
'number_of_steps': str(number_of_steps),
'number_of_steps': str(number_of_steps)
}

if selection_list:
encoder_fields['selection_list'] = ','.join(selection_list)
query_params['selection_list'] = ','.join(selection_list)
if rTol:
encoder_fields['rTol'] = str(rTol)
query_params['rTol'] = str(rTol)
if aTol:
encoder_fields['aTol'] = str(aTol)
query_params['aTol'] = str(aTol)

multidata = MultipartEncoder(fields=encoder_fields)
# TODO: do we need to change the headers?
headers = {'Content-Type': multidata.content_type}

try:
response = requests.post(url=endpoint, headers=headers, data=multidata)
response = requests.post(url=endpoint, headers=headers, data=multidata, params=query_params)
response.raise_for_status()
self._check_response(response)
return response.json()
Expand Down
213 changes: 184 additions & 29 deletions demos/bio_check_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T04:31:47.087066Z",
"start_time": "2024-08-02T04:31:47.084225Z"
"end_time": "2024-08-02T15:43:17.718411Z",
"start_time": "2024-08-02T15:43:17.715914Z"
}
},
"cell_type": "code",
Expand All @@ -24,8 +24,8 @@
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-08-02T04:31:47.480616Z",
"start_time": "2024-08-02T04:31:47.377162Z"
"end_time": "2024-08-02T15:43:18.533685Z",
"start_time": "2024-08-02T15:43:18.412520Z"
}
},
"source": [
Expand All @@ -38,8 +38,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T04:31:47.728677Z",
"start_time": "2024-08-02T04:31:47.726618Z"
"end_time": "2024-08-02T15:43:18.998923Z",
"start_time": "2024-08-02T15:43:18.997016Z"
}
},
"cell_type": "code",
Expand All @@ -60,8 +60,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T04:31:48.636819Z",
"start_time": "2024-08-02T04:31:48.389605Z"
"end_time": "2024-08-02T15:43:19.958431Z",
"start_time": "2024-08-02T15:43:19.524659Z"
}
},
"cell_type": "code",
Expand All @@ -81,8 +81,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T04:31:49.896494Z",
"start_time": "2024-08-02T04:31:49.894423Z"
"end_time": "2024-08-02T15:44:06.211050Z",
"start_time": "2024-08-02T15:44:06.209071Z"
}
},
"cell_type": "code",
Expand Down Expand Up @@ -115,13 +115,13 @@
]
}
],
"execution_count": 5
"execution_count": 6
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T04:14:19.421769Z",
"start_time": "2024-08-02T04:14:19.261974Z"
"end_time": "2024-08-02T15:44:07.561978Z",
"start_time": "2024-08-02T15:44:07.076772Z"
}
},
"cell_type": "code",
Expand All @@ -131,21 +131,43 @@
"submission_1 = verify.verify_sbml(sbml_filepath=sbml_fp, comparison_id=comparison_id, duration=duration, number_of_steps=nsteps, simulators=simulators)"
],
"id": "54fa1033a7c27056",
"outputs": [],
"execution_count": 7
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T15:44:13.684703Z",
"start_time": "2024-08-02T15:44:13.682441Z"
}
},
"cell_type": "code",
"source": "submission_1",
"id": "76899019bbcc9008",
"outputs": [
{
"ename": "NotImplementedError",
"evalue": "Submission of jobs with a SBML file is currently under development.",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mNotImplementedError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[0;32mIn[6], line 3\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;66;03m# submit a new verification \u001B[39;00m\n\u001B[0;32m----> 3\u001B[0m submission_1 \u001B[38;5;241m=\u001B[39m \u001B[43mverify\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mverify_sbml\u001B[49m\u001B[43m(\u001B[49m\u001B[43msbml_filepath\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43msbml_fp\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcomparison_id\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mcomparison_id\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mduration\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mduration\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mnumber_of_steps\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mnsteps\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43msimulators\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43msimulators\u001B[49m\u001B[43m)\u001B[49m\n",
"File \u001B[0;32m~/Desktop/repos/bio-check/demos/../bio_check/verifier.py:125\u001B[0m, in \u001B[0;36mVerifier.verify_sbml\u001B[0;34m(self, sbml_filepath, duration, number_of_steps, simulators, include_outputs, comparison_id, rTol, aTol, selection_list)\u001B[0m\n\u001B[1;32m 122\u001B[0m endpoint \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_format_endpoint(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mverify-sbml\u001B[39m\u001B[38;5;124m'\u001B[39m)\n\u001B[1;32m 124\u001B[0m \u001B[38;5;66;03m# TODO: fix and remove this\u001B[39;00m\n\u001B[0;32m--> 125\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mNotImplementedError\u001B[39;00m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mSubmission of jobs with a SBML file is currently under development.\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 127\u001B[0m \u001B[38;5;66;03m# configure params\u001B[39;00m\n\u001B[1;32m 128\u001B[0m _id \u001B[38;5;241m=\u001B[39m comparison_id \u001B[38;5;129;01mor\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mbio_check-request-\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;241m+\u001B[39m \u001B[38;5;28mstr\u001B[39m(uuid4())\n",
"\u001B[0;31mNotImplementedError\u001B[0m: Submission of jobs with a SBML file is currently under development."
]
"data": {
"text/plain": [
"{'job_id': 'test_notebook_sbml0_c5c87ae7-b503-4d56-9bed-e774a894f036',\n",
" 'status': 'PENDING',\n",
" 'timestamp': '2024-08-02 15:44:07.406931',\n",
" 'comparison_id': None,\n",
" 'path': 'uploads/test_notebook_sbml0_c5c87ae7-b503-4d56-9bed-e774a894f036/BIOMD0000000012_url.xml',\n",
" 'duration': 10,\n",
" 'n_steps': 100,\n",
" 'simulators': ['amici,copasi,tellurium'],\n",
" 'include_output': True,\n",
" 'rTol': None,\n",
" 'aTol': None,\n",
" 'selection_list': None}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 6
"execution_count": 8
},
{
"metadata": {
Expand Down Expand Up @@ -538,8 +560,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T04:31:56.703286Z",
"start_time": "2024-08-02T04:31:54.782228Z"
"end_time": "2024-08-02T15:43:32.958192Z",
"start_time": "2024-08-02T15:43:30.762564Z"
}
},
"cell_type": "code",
Expand Down Expand Up @@ -570,7 +592,7 @@
"output_type": "display_data"
}
],
"execution_count": 6
"execution_count": 5
},
{
"metadata": {
Expand Down Expand Up @@ -1159,13 +1181,146 @@
],
"execution_count": 9
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T15:23:51.851257Z",
"start_time": "2024-08-02T15:23:51.849131Z"
}
},
"cell_type": "code",
"source": "verify",
"id": "15c5f2d38e041bc8",
"outputs": [
{
"data": {
"text/plain": [
"<bio_check.verifier.Verifier at 0x34b8c0940>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 10
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T15:27:59.702110Z",
"start_time": "2024-08-02T15:27:59.699518Z"
}
},
"cell_type": "code",
"source": [
"from requests_toolbelt.multipart.encoder import MultipartEncoder\n",
"\n",
"endpoint = verify._format_endpoint(\"verify-sbml\")\n",
"\n",
"endpoint"
],
"id": "2a89a3e3f6e6a0f8",
"outputs": [
{
"data": {
"text/plain": [
"'https://biochecknet.biosimulations.org/verify-sbml'"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 11
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T15:36:54.728158Z",
"start_time": "2024-08-02T15:36:54.724377Z"
}
},
"cell_type": "code",
"source": [
"fields = {\n",
" 'uploaded_file': (sbml_fp.split('/')[-1], open(sbml_fp, 'rb'), 'application/octet-stream'),\n",
" 'simulators': ','.join(simulators),\n",
" 'include_outputs': str(True).lower(),\n",
"}\n",
"\n",
"query_params = {\n",
" 'duration': str(duration),\n",
" 'number_of_steps': str(600),\n",
"}\n",
"\n",
"multipart = MultipartEncoder(fields=fields)\n",
"headers = {'Content-Type': multipart.content_type}"
],
"id": "58410b769e239c04",
"outputs": [],
"execution_count": 19
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T15:37:17.494061Z",
"start_time": "2024-08-02T15:37:16.086644Z"
}
},
"cell_type": "code",
"source": [
"import requests \n",
"\n",
"resp = requests.post(url=endpoint, headers=headers, data=multipart, params=query_params)"
],
"id": "f726873792bcaf04",
"outputs": [],
"execution_count": 20
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T15:37:19.051144Z",
"start_time": "2024-08-02T15:37:19.048436Z"
}
},
"cell_type": "code",
"source": "resp.json()",
"id": "fd3f1f43d470db99",
"outputs": [
{
"data": {
"text/plain": [
"{'job_id': 'utc_comparison_omex_51a58a9a-4d5e-487d-8b18-dd51ac798710',\n",
" 'status': 'PENDING',\n",
" 'timestamp': '2024-08-02 15:37:16.602695',\n",
" 'comparison_id': None,\n",
" 'path': 'uploads/utc_comparison_omex_51a58a9a-4d5e-487d-8b18-dd51ac798710/BIOMD0000000012_url.xml',\n",
" 'duration': 10,\n",
" 'n_steps': 600,\n",
" 'simulators': ['copasi', 'tellurium'],\n",
" 'include_output': True,\n",
" 'rTol': None,\n",
" 'aTol': None,\n",
" 'selection_list': None}"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 21
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "",
"id": "15c5f2d38e041bc8"
"source": "veri",
"id": "1383441af0519303"
}
],
"metadata": {
Expand Down

0 comments on commit dd8e046

Please sign in to comment.