Add dataset, slurm_id, and FAILED status to models

Enhanced the models with new fields: a dataset field for Experiment Parameters and a slurm_id for Jobs. Introduced a FAILED status for the JobStatus enum. Updated functionality to handle datasets and trigger job creation based on dataset status.
This commit is contained in:
GotthardG
2025-04-29 22:52:36 +02:00
parent 9af2e84f9e
commit 57de665c7b
8 changed files with 202 additions and 55 deletions

View File

@ -3,8 +3,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-04-29T11:59:40.825956Z",
"start_time": "2025-04-29T11:59:40.822492Z"
"end_time": "2025-04-29T20:17:17.478562Z",
"start_time": "2025-04-29T20:17:16.842590Z"
}
},
"cell_type": "code",
@ -43,12 +43,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.1.1a1\n",
"0.1.1a2\n",
"https://localhost:8000\n"
]
}
],
"execution_count": 31
"execution_count": 1
},
{
"metadata": {},
@ -427,21 +427,21 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-04-29T12:00:18.905592Z",
"start_time": "2025-04-29T12:00:18.903773Z"
"end_time": "2025-04-29T20:17:43.335654Z",
"start_time": "2025-04-29T20:17:43.333828Z"
}
},
"cell_type": "code",
"source": "sample_id = 250",
"source": "sample_id = 230",
"id": "54d4d46ca558e7b9",
"outputs": [],
"execution_count": 32
"execution_count": 2
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-04-29T12:00:20.537319Z",
"start_time": "2025-04-29T12:00:20.510157Z"
"end_time": "2025-04-29T20:17:46.414835Z",
"start_time": "2025-04-29T20:17:46.379138Z"
}
},
"cell_type": "code",
@ -493,7 +493,7 @@
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n",
"/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n",
" warnings.warn(\n",
"DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/250/events HTTP/1.1\" 200 412\n"
"DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/230/events HTTP/1.1\" 200 413\n"
]
},
{
@ -503,9 +503,9 @@
"Payload being sent to API:\n",
"{\"event_type\":\"Collecting\"}\n",
"API response:\n",
"('id', 250)\n",
"('sample_name', 'Sample250')\n",
"('position', 9)\n",
"('id', 230)\n",
"('sample_name', 'Sample230')\n",
"('position', 16)\n",
"('puck_id', 30)\n",
"('crystalname', None)\n",
"('proteinname', None)\n",
@ -513,19 +513,22 @@
"('priority', None)\n",
"('comments', None)\n",
"('data_collection_parameters', None)\n",
"('events', [SampleEventResponse(event_type='Mounting', id=490, sample_id=250, timestamp=datetime.datetime(2025, 4, 28, 13, 42)), SampleEventResponse(event_type='Collecting', id=491, sample_id=250, timestamp=datetime.datetime(2025, 4, 29, 12, 0, 20, 528955))])\n",
"('events', [SampleEventResponse(event_type='Mounting', id=453, sample_id=230, timestamp=datetime.datetime(2025, 4, 28, 13, 22)), SampleEventResponse(event_type='Collecting', id=454, sample_id=230, timestamp=datetime.datetime(2025, 4, 29, 20, 17, 46, 405264))])\n",
"('mount_count', 0)\n",
"('unmount_count', 0)\n"
]
}
],
"execution_count": 33
"execution_count": 3
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-04-29T14:27:46.730515Z",
"start_time": "2025-04-29T14:27:46.622922Z"
}
},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"### not working\n",
"with aareDBclient.ApiClient(configuration) as api_client:\n",
@ -541,13 +544,27 @@
" except ApiException as e:\n",
" print(\"Exception when calling get_last_sample_event: %s\\n\" % e)\n"
],
"id": "f1d171700d6cf7fe"
"id": "f1d171700d6cf7fe",
"outputs": [
{
"ename": "AttributeError",
"evalue": "'SamplesApi' object has no attribute 'get_last_sample_event_samples_samples_sample_id_events_last_get'",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mAttributeError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[0;32mIn[48], line 8\u001B[0m\n\u001B[1;32m 4\u001B[0m api_instance \u001B[38;5;241m=\u001B[39m aareDBclient\u001B[38;5;241m.\u001B[39mSamplesApi(api_client)\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 7\u001B[0m \u001B[38;5;66;03m# Get the last sample event\u001B[39;00m\n\u001B[0;32m----> 8\u001B[0m last_event_response \u001B[38;5;241m=\u001B[39m \u001B[43mapi_instance\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget_last_sample_event_samples_samples_sample_id_events_last_get\u001B[49m(\u001B[38;5;241m27\u001B[39m)\n\u001B[1;32m 9\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe response of get_last_sample_event:\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 10\u001B[0m pprint(last_event_response)\n",
"\u001B[0;31mAttributeError\u001B[0m: 'SamplesApi' object has no attribute 'get_last_sample_event_samples_samples_sample_id_events_last_get'"
]
}
],
"execution_count": 48
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-04-29T12:21:22.613961Z",
"start_time": "2025-04-29T12:21:22.585856Z"
"end_time": "2025-04-29T20:17:52.059793Z",
"start_time": "2025-04-29T20:17:51.939047Z"
}
},
"cell_type": "code",
@ -618,7 +635,7 @@
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): 127.0.0.1:8000\n",
"/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n",
" warnings.warn(\n",
"DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"POST /samples/250/upload-images HTTP/1.1\" 200 204\n"
"DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"POST /samples/230/upload-images HTTP/1.1\" 200 205\n"
]
},
{
@ -628,11 +645,11 @@
"Uploading after_dc.jpeg.jpg...\n",
"API Response for after_dc.jpeg.jpg:\n",
"200\n",
"{'pgroup': 'p20003', 'sample_id': 250, 'sample_event_id': 492, 'filepath': 'images/p20003/2025-04-29/Dewar Five/PKK007/9/Collecting_2025-04-29_12-00-30/after_dc.jpeg.jpg', 'status': 'active', 'comment': None, 'id': 2}\n"
"{'pgroup': 'p20003', 'sample_id': 230, 'sample_event_id': 454, 'filepath': 'images/p20003/2025-04-29/Dewar Five/PKK007/16/Collecting_2025-04-29_20-17-46/after_dc.jpeg.jpg', 'status': 'active', 'comment': None, 'id': 1}\n"
]
}
],
"execution_count": 36
"execution_count": 4
},
{
"metadata": {},
@ -645,8 +662,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-04-29T12:21:30.879657Z",
"start_time": "2025-04-29T12:21:30.855622Z"
"end_time": "2025-04-29T20:17:56.494919Z",
"start_time": "2025-04-29T20:17:56.469538Z"
}
},
"cell_type": "code",
@ -761,7 +778,7 @@
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n",
"/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n",
" warnings.warn(\n",
"DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/250/experiment_parameters HTTP/1.1\" 200 860\n"
"DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/230/experiment_parameters HTTP/1.1\" 200 875\n"
]
},
{
@ -769,11 +786,71 @@
"output_type": "stream",
"text": [
"API Response:\n",
"run_number=2 beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.1, chi=0.0, phi=10.0, number_of_images=3600, exposure_time_s=0.02), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) sample_id=250 id=2\n"
"run_number=1 beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.1, chi=0.0, phi=10.0, number_of_images=3600, exposure_time_s=0.02), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=None sample_id=230 id=1\n"
]
}
],
"execution_count": 37
"execution_count": 5
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-04-29T20:29:27.657874Z",
"start_time": "2025-04-29T20:29:27.623737Z"
}
},
"cell_type": "code",
"source": [
"from datetime import datetime\n",
"\n",
"sample_id = sample_id\n",
"run_id = 1\n",
"\n",
"def test_mark_run_written(sample_id, run_id, configuration):\n",
" # Prepare your dataset dict as required by your API (.dict() results if using Pydantic model)\n",
" dataset_payload = {\n",
" \"filepath\": \"/das/work/p11/p11206/raw_data/vincent/20250415_6D_SLS2_1st_data/20250415_fullbeam_dtz220_Lyso102_again_360deg\",\n",
" \"status\": \"written\",\n",
" \"written_at\": datetime.now().isoformat()\n",
" }\n",
"\n",
" # The API method and argument names may differ if autogenerated — adjust accordingly\n",
" with aareDBclient.ApiClient(configuration) as api_client:\n",
" api_instance = aareDBclient.SamplesApi(api_client)\n",
" try:\n",
" api_response = api_instance.update_dataset_for_experiment_run(\n",
" sample_id=sample_id, run_id=run_id, datasets=dataset_payload\n",
" )\n",
" print(\"Dataset updated successfully:\")\n",
" print(api_response)\n",
" except ApiException as e:\n",
" print(f\"API call failed: {e}\")\n",
"\n",
"# Usage example (replace with your actual IDs and configuration):\n",
"test_mark_run_written(sample_id, run_id, configuration)"
],
"id": "77793ecd843c1ef3",
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n",
"/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n",
" warnings.warn(\n",
"DEBUG:urllib3.connectionpool:https://localhost:8000 \"PATCH /samples/update-dataset/230/1 HTTP/1.1\" 200 1056\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dataset updated successfully:\n",
"run_number=1 beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.1, chi=0.0, phi=10.0, number_of_images=3600, exposure_time_s=0.02), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=Datasets(filepath='/das/work/p11/p11206/raw_data/vincent/20250415_6D_SLS2_1st_data/20250415_fullbeam_dtz220_Lyso102_again_360deg', status='written', written_at=datetime.datetime(2025, 4, 29, 22, 29, 27, 626524)) sample_id=230 id=1\n"
]
}
],
"execution_count": 13
},
{
"metadata": {