-
Notifications
You must be signed in to change notification settings - Fork 7
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
Feature/update computational asset definition #363
base: develop
Are you sure you want to change the base?
Feature/update computational asset definition #363
Conversation
Sorry for the delay in reviewing. It's been very hectic. I will review this at the latest next week. |
I noticed no API endpoints have been added. Is this deliberate? |
Yes, it is deliberated, we just change the computational asset model adding some needed properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I think it looks fine. For documentation purposes/users, it would be good to document examples and the units used for each field.
@@ -42,3 +70,29 @@ class RelationshipConfig(AIAsset.RelationshipConfig): | |||
deserializer=FindByNameDeserializer(ComputationalAssetType), | |||
example="storage", | |||
) | |||
|
|||
cpu: list[Cpu] | None = OneToMany( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense for the components (accelerator, cpu, etc.) to be many-to-many? E.g., one CPU model may be used in different computational assets. Perhaps this is not common enough to avoid duplication in the database?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hbonell-iti @soniasantiago It's marked ready to (re)review but I would like to still know if what's the thought process here. It doesn't look like Cpu
is intended to specify one particular unit, but rather a model. In which case I assume it can occur in different computational assets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for not answering to your comment before.
As you say, it's true that one CPU model could be used in different computational assets. However, due to the different attributes of the CPU model and its possible values, we believe it won't happen too often. This is the main reason why the relation is defined one-to-many.
However, if you think this is not the best approach, let us know and we will do in the other way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine going with your judgement, I just wanted to ensure it wasn't an oversight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect. I just wanted to make sure that this is done in the right way. Thanks for checking this!
@PGijsbers Besides the open comments, since the computational asset model has changed, I'm not sure if we should implement the corresponding database migration script. I have checked that in the production instance there is only one example computational asset defined, so dropping the computational_asset table and recreating it might be enough. But, if not, let us know and we will do that. For the "location" relationship, when we deployed in our dev environment this version of the API REST we had to apply in the database the following modification:
so we may have to define this in a database migration script. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not catching this the first time around, but changes to existing tables also need database schema migration scripts. I linked the docs in another comment. Let me know if you need more help.
I would recommend taking the following steps:
- Merge
develop
into this branch, or rebase (this is to ensure you have all current migration scripts). - Make sure you can upload a computational asset through your local rest API (preferably also automate this in a unit test). This verifies the current schema works as intended, so you can build a migration script off that.1
- Then go to the develop branch to recreate the dataset with the current schema:
docker compose --profile "*" down
git checkout develop
docker compose up -d
- Then go back to this branch and run the migration script you created.
- If the migration script is correct, you should still be able to upload a computational asset. If it is incorrect, you will likely get an error telling what column(s) are missing. In that case, update the script and repeat the last two steps.
Here's an example migration script adding the "os" column. I would recommend to extend it to contain all changes of this PR into the same Alembic migration:
"""add os to computationalasset
Revision ID: 35d4190fa3c6
Revises: 0f2fe1324047
Create Date: 2024-11-20 14:15:48.456218
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy import String, Column
from database.model.field_length import NORMAL
# revision identifiers, used by Alembic.
revision: str = '35d4190fa3c6'
down_revision: Union[str, None] = '0f2fe1324047'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.add_column(
f"computational_asset",
Column("os", String(NORMAL)),
)
def downgrade() -> None:
pass
To recreate the database at any point (with loss of data):
docker compose down
./scripts/clean.sh
docker compose up -d
Footnotes
-
I haven't yet experimented with the automatic generation of migration scripts, but it might be worth looking into. ↩
computational_asset_identifier: int | None = Field( | ||
sa_column=Column(Integer, ForeignKey("computational_asset.identifier", ondelete="CASCADE")) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For changes to tables which already exist in the database, we need to add a database schema migration script. Please see this documentation for more information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks for the reference!
) | ||
|
||
|
||
class CpuORM(CpuBase, table=True): # type: ignore [call-arg] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I read the metadata model, CPU should be a subclass of AIoD concept?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for accelerator, and other added items?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We thought about these entities to be similarly as "location". That is, not a subclass of AIoD concept, at least at the implementation level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe I misunderstand how to read
this documentation. I am having a meeting with Antonis about this next week.
The migration file was added. Is there anything else to add to the pull request? |
Add some properties and models from computational asset definition:
Models:
Properties: