Skip to content

Commit

Permalink
Practice Qserver API
Browse files Browse the repository at this point in the history
  • Loading branch information
XPD Operator committed Apr 2, 2024
1 parent f4743d4 commit fecf1c5
Show file tree
Hide file tree
Showing 2 changed files with 618 additions and 4 deletions.
311 changes: 309 additions & 2 deletions scripts/notes/.ipynb_checkpoints/qserver_zmq_002-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,320 @@
"~$ queue-monitor --zmq-control-addr tcp://xf28id2-ca2:60615 --zmq-info-addr tcp://xf28id2-ca2:60625"
]
},
{
"cell_type": "markdown",
"id": "2e5e0f53-862f-439d-bacb-42315b24623e",
"metadata": {},
"source": [
"## 3. Change zmq_single_request to REManagerAPI\n",
"##### https://blueskyproject.io/bluesky-queueserver-api/usage.html\n",
"##### https://blueskyproject.io/bluesky-queueserver-api/api-reference.html#generation-of-queue-items\n",
"##### https://blueskyproject.io/bluesky-queueserver-api/api-reference.html#synchronous-communication-with-0mq-server\n",
"##### https://blueskyproject.io/bluesky-queueserver-api/generated/bluesky_queueserver_api.BPlan.html#bluesky_queueserver_api.BPlan"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "f4776bbd-26cd-4c0d-bb78-3db403df1fb4",
"metadata": {},
"outputs": [],
"source": [
"from bluesky_queueserver_api.zmq import REManagerAPI\n",
"from bluesky_queueserver_api import BPlan, BInst"
]
},
{
"cell_type": "markdown",
"id": "b0965d8b-63ec-4c32-9e5a-b8d53f592af0",
"metadata": {},
"source": [
"#### At 1LL09"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d286bbde-cf9d-43e6-88e0-89d8de3ba921",
"metadata": {},
"outputs": [],
"source": [
"RM = REManagerAPI(zmq_control_addr='tcp://localhost:60615')"
]
},
{
"cell_type": "markdown",
"id": "939cc4a4-5b9e-4906-917f-5ade0056de3c",
"metadata": {},
"source": [
"#### At XPD beamline"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c9e41fc-1729-431f-9b77-99a45c9176d9",
"metadata": {},
"outputs": [],
"source": [
"RM = REManagerAPI(zmq_control_addr='tcp://xf28id2-ca2:60615', zmq_info_addr='tcp://xf28id2-ca2:60625')"
]
},
{
"cell_type": "markdown",
"id": "8d7ee739-8656-4d3d-8e4d-a960f2539b18",
"metadata": {},
"source": [
"### Commonly used RM API\n",
"##### https://blueskyproject.io/bluesky-queueserver-api/api-reference.html#generation-of-queue-items"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "88df8fb5-c821-463e-bab4-d48a854edb95",
"metadata": {},
"outputs": [],
"source": [
"RM.status()\n",
"RM.environment_close()\n",
"RM.environment_open()\n",
"RM.queue_get()\n",
"RM.queue_clear()\n",
"RM.queue_start()\n",
"RM.queue_stop()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "453a8eed-844d-41c3-8ea2-ae4fe3cf762b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['LED', 'UV_shutter', 'dds1', 'dds1_p1', 'dds1_p2', 'dds2', 'dds2_p1', 'dds2_p2', 'det', 'det4', 'deuterium', 'halogen', 'motor', 'noisy_det', 'qepro', 'ultra1', 'ultra2'])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"RM.devices_allowed()['devices_allowed'].keys()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "edd4d9aa-83f7-42a8-8020-ee5d56ce8b75",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['LED_off', 'LED_on', 'count', 'deuterium_off', 'deuterium_on', 'halogen_off', 'halogen_on', 'insitu_test', 'reset_pumps2', 'scan', 'set_group_infuse', 'set_group_infuse2', 'set_group_withdraw', 'setup_collection_q', 'shutter_close', 'shutter_open', 'sleep_sec_q', 'start_group_infuse', 'start_group_withdraw', 'stop_group', 'take_a_uvvis_csv_q', 'take_ref_bkg_q', 'wait_equilibrium', 'wait_equilibrium2', 'xray_uvvis_plan'])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"RM.plans_allowed()['plans_allowed'].keys()"
]
},
{
"cell_type": "markdown",
"id": "995b53b4-75d1-495a-a1b3-0d0e1fafd71a",
"metadata": {},
"source": [
"### A quick example"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "4b6857f2-a889-4854-b18a-8a1dea8e78aa",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'success': True,\n",
" 'msg': '',\n",
" 'qsize': 3,\n",
" 'item': {'item_type': 'plan',\n",
" 'name': 'count',\n",
" 'args': [['det', 'noisy_det']],\n",
" 'kwargs': {'num': 0, 'delay': 1},\n",
" 'user': 'Queue Server API User',\n",
" 'user_group': 'primary',\n",
" 'item_uid': '971ceacf-8516-416a-9fa9-ef36f9f5e934'}}"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plan0 = BPlan('sleep_sec_q', 60)\n",
"plan1 = BPlan(\"count\", [\"det\", \"noisy_det\"], num=0, delay=1)\n",
"inst1 = BInst(\"queue_stop\")\n",
"\n",
"RM.item_add(plan0)\n",
"RM.item_add(inst1)\n",
"RM.item_add(plan1)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "51785db6-9165-4273-842d-9dd452fd7dc9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'success': True,\n",
" 'msg': '',\n",
" 'items': [{'item_type': 'plan',\n",
" 'name': 'sleep_sec_q',\n",
" 'args': [60],\n",
" 'user': 'Queue Server API User',\n",
" 'user_group': 'primary',\n",
" 'item_uid': '39687150-9825-40a1-82a2-571c64b1abf2'},\n",
" {'item_type': 'instruction',\n",
" 'name': 'queue_stop',\n",
" 'user': 'Queue Server API User',\n",
" 'user_group': 'primary',\n",
" 'item_uid': 'e7d4a3e3-5853-42f6-ab22-1524798209ea'},\n",
" {'item_type': 'plan',\n",
" 'name': 'count',\n",
" 'args': [['det', 'noisy_det']],\n",
" 'kwargs': {'num': 0, 'delay': 1},\n",
" 'user': 'Queue Server API User',\n",
" 'user_group': 'primary',\n",
" 'item_uid': '971ceacf-8516-416a-9fa9-ef36f9f5e934'}],\n",
" 'running_item': {},\n",
" 'plan_queue_uid': '564ff1f1-0976-443d-8458-3e1c11b02fe9'}"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"RM.queue_get()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "486e0e16-bbda-4ac4-8359-601515cc572f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'success': True, 'msg': ''}"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"RM.queue_clear()"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "b25ff432-1729-46f1-8e23-2fee1cb9f8de",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'success': True, 'msg': ''}"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"RM.queue_start()"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "7b14595e-1172-4aa5-8bc8-f82c2de799fd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'success': True, 'msg': ''}"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"RM.queue_stop()"
]
},
{
"cell_type": "markdown",
"id": "d02435ba-e915-42c7-af50-03cc515fb90c",
"metadata": {},
"source": [
"### Practice adding flow plans"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "13380e59-d243-4d80-a4a7-542c5192a508",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6bf0484a-a0b1-4294-a0a3-162fb5949d0a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f7df838-3d64-479e-8570-3cf1909d280b",
"metadata": {},
"outputs": [],
"source": []
},
{
"attachments": {},
"cell_type": "markdown",
"id": "c1098d2d-02d9-41e0-8411-84ba2797fbe8",
"metadata": {},
"source": [
"## 3. Open another terminal for BSUI ipython (Optional)\n",
"## 999. Open another terminal for BSUI ipython (Optional)\n",
"\n",
"~$ BS_ENV=2023-1.3-py310-tiled bsui"
]
Expand Down Expand Up @@ -972,7 +1279,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit fecf1c5

Please sign in to comment.