self-driving-lab-demo
self-driving-lab-demo copied to clipboard
pydantic minimal working example for experiment input validation (and some serverless options)
From https://github.com/sparks-baird/self-driving-lab-demo/discussions/127#discussioncomment-4199244 by @rekumar:
Have you looked at pydantic for this kind of thing? Its pretty nice, clear to work with, and stitches into API's very cleanly. Example for validating job submission to our API:
Defining our Data Model: https://github.com/CederGroupHub/alab_management/blob/94d02870623eb198e663e7789021e7f3596768c3/alab_management/experiment_view/experiment.py
Validating incoming jobs against the Data Model https://github.com/CederGroupHub/alab_management/blob/94d02870623eb198e663e7789021e7f3596768c3/alab_management/dashboard/routes/experiment.py#L14-L29
This would be at the application side (perhaps in the observation function).
Once pydantic is implemented in the codebase, I'd like to figure out a way to put a virtual- or hardware-based "firewall" in-between the user requesting the experiment and the device(s) carrying out the commands, in line with https://github.com/sparks-baird/self-driving-lab-demo/discussions/127#discussioncomment-4200086:
For SDLs with multiple steps (i.e. multiple pieces of hardware that require separate communication), I lean toward the idea of the user communicating with a central processor as a "firewall" of sorts (e.g., physical hardware or cloud-based server) rather than having the user directly communicate with the individual pieces of hardware. Something where the scope of users that can change code on the physical hardware, server, etc. is narrower than the scope of users that can send requests to it.
I.e., a way to expose a controlled instance of the API pinned to a specific package version via HTTP requests, for free.
Google search: host python package api for free
- https://www.youtube.com/watch?v=z6q9kug0PL0
- Maybe pythonanywhere? I think I've come across this before and it looks interesting. Saw it (again?) just now on a list at https://dev.to/yash_makan/4-best-python-web-app-hosting-services-for-freewith-complete-process-57nb. EDIT: pythonanywhere free version is restricted to a list of whitelisted websites. Vercel might be the better option (see below)
Vercel
- https://towardsdatascience.com/how-to-deploy-a-python-serverless-function-to-vercel-f43c8ca393a0
- https://vercel.com/docs/concepts/projects/environment-variables (set an API key as an environment variable)
- https://github.com/vercel/vercel/discussions/5709#discussioncomment-4202386 (pass API key as query string and check inside serverless function)
On a related note, I'm interested in creating an example with the light-mixing demo and alab_management.
cc Matthias Albert Popp, re OPC-UA