Skip to content
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

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

hbonell-iti
Copy link
Collaborator

Add some properties and models from computational asset definition:

Models:

  • Accelerator
  • CPU
  • Memory
  • Storage

Properties:

  • os
  • kernel
  • pricing_scheme
  • cpu
  • memory
  • accelerator
  • storage

@hbonell-iti hbonell-iti requested a review from PGijsbers October 7, 2024 11:36
@PGijsbers
Copy link
Collaborator

Sorry for the delay in reviewing. It's been very hectic. I will review this at the latest next week.

@PGijsbers
Copy link
Collaborator

I noticed no API endpoints have been added. Is this deliberate?

@hbonell-iti
Copy link
Collaborator Author

Yes, it is deliberated, we just change the computational asset model adding some needed properties.

Copy link
Collaborator

@PGijsbers PGijsbers left a 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(
Copy link
Collaborator

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?

Copy link
Collaborator

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?

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.

Copy link
Collaborator

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.

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!

src/database/model/computational_asset/cpu.py Outdated Show resolved Hide resolved
src/database/model/computational_asset/accelerator.py Outdated Show resolved Hide resolved
@hbonell-iti hbonell-iti marked this pull request as draft November 6, 2024 09:32
@hbonell-iti hbonell-iti marked this pull request as ready for review November 13, 2024 16:24
@soniasantiago
Copy link

soniasantiago commented Nov 19, 2024

@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:

SET FOREIGN_KEY_CHECKS = 0;

ALTER TABLE location ADD COLUMN computational_asset_identifier INT NULL;

CREATE INDEX ix_location_computational_asset_identifier ON location(computational_asset_identifier);

ALTER TABLE location 
ADD CONSTRAINT fk_location_computational_asset
FOREIGN KEY (computational_asset_identifier)
REFERENCES computational_asset(identifier)
ON DELETE CASCADE;
 
SET FOREIGN_KEY_CHECKS = 1;

so we may have to define this in a database migration script.

Copy link
Collaborator

@PGijsbers PGijsbers left a 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

  1. I haven't yet experimented with the automatic generation of migration scripts, but it might be worth looking into.

Comment on lines +121 to +123
computational_asset_identifier: int | None = Field(
sa_column=Column(Integer, ForeignKey("computational_asset.identifier", ondelete="CASCADE"))
)
Copy link
Collaborator

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.

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]
Copy link
Collaborator

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?

Copy link
Collaborator

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?

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.

Copy link
Collaborator

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.

@hbonell-iti
Copy link
Collaborator Author

The migration file was added. Is there anything else to add to the pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants