pytorch-lightning
pytorch-lightning copied to clipboard
PoC: Investigate support for database
What does this PR do?
This PR explores SQModel integration within the Lightning App framework to simplify database manipulation.
# Why SQModel
From Sebastián Ramírez, SQLModel removes boilerplate to interact with database from Python. Its SQLModel is a SQLAlchemy model and a Pydantic model ✨ Which makes it very easy to use with FastAPI.
My personal opinion is that it removes most of the boilerplate to manipulate the specs from control-plane to data plane and reconciliation.
https://user-images.githubusercontent.com/12861981/183063574-63e517ed-009b-4adc-b920-9dc3d815ac35.mov
https://user-images.githubusercontent.com/12861981/183063620-8bc5cc6b-7483-4ba1-a0e4-819e48613c84.mov
Another benefit is the ease to access reading and writing from / to the database for the users.
Reading
class FlowDB(LightningFlow):
def run(self):
if self.schedule("...."):
self.read_from_db()
def read_from_db(self):
with Session(self.engine) as session:
....
return ...
Writing to the DB through the Rest API
Associated with the configure_api
PR https://github.com/Lightning-AI/lightning/pull/13945, you get full pydantic validation + database entries.
class FlowDB(LightningFlow):
def run(self):
if self.schedule("...."):
self.read_from_db()
def something_handler(self, config: SomethingConfig):
with Session(self.engine) as session:
....
return ...
def configure_api(self):
return [Post("/create_something", self.something_handler)
Fixes #<issue_number>
Does your PR introduce any breaking changes? If yes, please list them.
Before submitting
- [ ] Was this discussed/approved via a GitHub issue? (not for typos and docs)
- [ ] Did you read the contributor guideline, Pull Request section?
- [ ] Did you make sure your PR does only one thing, instead of bundling different changes together?
- [ ] Did you make sure to update the documentation with your changes? (if necessary)
- [ ] Did you write any new necessary tests? (not for typos and docs)
- [ ] Did you verify new and existing tests pass locally with your changes?
- [ ] Did you list all the breaking changes introduced by this pull request?
- [ ] Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)
PR review
Anyone in the community is welcome to review the PR. Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:
- [ ] Is this pull request ready for review? (if not, please submit in draft mode)
- [ ] Check that all items from Before submitting are resolved
- [ ] Make sure the title is self-explanatory and the description concisely explains the PR
- [ ] Add labels and milestones (and optionally projects) to the PR so it can be classified
Did you have fun?
Make sure you had fun coding 🙃
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need further help see our docs: https://pytorch-lightning.readthedocs.io/en/latest/generated/CONTRIBUTING.html#pull-request or ask the assistance of a core contributor here or on Slack. Thank you for your contributions.
This pull request is going to be closed. Please feel free to reopen it create a new from the actual master.
@tchaton is this still relevant or can this be closed? Research Studio does have databases, right?