Skip to content

Validation proposal #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/db/validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from sqlalchemy import Column, Integer, String, Table, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.postgresql import ARRAY # Using PostgreSQL's array type for sets

Base = declarative_base()

class Validation(Base):
__tablename__ = "validations"

id = Column(Integer, primary_key=True, index=True)
entity_type = Column(String, nullable=False, index=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand :( . Can you give an example of 1 instance of this ? and how it would be consumed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be easier to look at the schema rather than the data model. So let's say the user contributes a new morphology. The validation logic looks up the morphology entity type in the table then applies the "must_pass_to_upload" validations. If these are successful it runs the validations in "must_run_upon_upload" which annotates the entity, and "must_pass_to_simulate" which generates additional validations needed for the artifact to be simulated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, then it is not a validation, it is rather something like a "validation plan".

also what does the list of string contains ? I know it is a list of validations. but how do we go from a string to the actual execution of a code ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the validation plan schema stored in the database. The string contains a relative path in a github repo, for example "/morphologies/validate_morphology.py" I wrote a simple "validate_morphology.py" script that sees if it can be read in by NeuroM and returns an error if not. There will need to be some support logic that processes the lists, which I can add to entitycore once we are satisfied with this plan.


# Using PostgreSQL ARRAY type to store sets of strings
# Note: This doesn't guarantee uniqueness like Python sets do - application logic would need to enforce that
must_pass_to_upload = Column(ARRAY(String), nullable=True)
must_run_upon_upload = Column(ARRAY(String), nullable=True)
must_pass_to_simulate = Column(ARRAY(String), nullable=True)

def __repr__(self):
return f"<Validation(entity_type='{self.entity_type}')>"

# Helper methods to work with the array fields as sets
def get_must_pass_to_upload(self):
return set(self.must_pass_to_upload) if self.must_pass_to_upload else set()

def set_must_pass_to_upload(self, value_set):
self.must_pass_to_upload = list(value_set) if value_set else None

def get_must_run_upon_upload(self):
return set(self.must_run_upon_upload) if self.must_run_upon_upload else set()

def set_must_run_upon_upload(self, value_set):
self.must_run_upon_upload = list(value_set) if value_set else None

def get_must_pass_to_simulate(self):
return set(self.must_pass_to_simulate) if self.must_pass_to_simulate else set()

def set_must_pass_to_simulate(self, value_set):
self.must_pass_to_simulate = list(value_set) if value_set else None
10 changes: 10 additions & 0 deletions app/schemas/validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pydantic import BaseModel, ConfigDict
from typing import Optional, Set

class Validation(BaseModel):
entity_type: str # from predetermined vocabulary (an entity class in db)
must_pass_to_upload: Optional[Set[str]] = None # set of validation script paths in  github repo. Each has a function with output pass or fail.  Optional output (log fails)  If any fails, the entity can’t be uploaded to the database.
must_run_upon_upload: Optional[Set[str]] = None #set of validation script paths in github repo that will be launched when uploading an artifact. The result will be available as annotation to the entity.

must_pass_to_simulate: Optional[Set[str]] = None #set of validation script paths in github repo that must pass to simulate. Will be launched when uploading an artifact, the result will be available as annotation to the entity.

Loading