Substra/substra-backend

Streamline model view

Closed this issue · 5 comments

The model view has a lot of peculiarities:

  • /model doesn't return models per se, but instead returns the list of all traintuples/composite traintuples/aggregatetuples each with the associated certified testtuple (even though this concept doesn't really exists anymore)
  • /model/<traintuple_key> only works for traintuples and returns the traintuple and all the linked testtuples. It also creates a local cache of each outModel. It fails with a 500 if the key doesn't match a traintuple but rather a composite traintuple for example.
  • /model/<tuple_key>/details (where tuple_key is either a composite_traintuple_key, a traintuple_key or an aggregate_key) returns the tuple and all the linked testtuples
  • /model/<model_hash>/file streams the content of an outModel

A streamlined schema could be:

  • /model returns the list of all traintuples/composite traintuples/aggregatuples
  • /model/<tuple_key> returns the matching traintuple / composite traintuple / aggregatetuple with all linked testuples
  • /model/<tuple_key>/file streams the content of the outModel (for traintuple / aggregatetuple) or the content of the outTrunkModel (for composite traintuple)

It seems that, as of writing this comment, /model/<key> doesn't work at all. We compare the traintuple key with the model file hash: the comparison always fails:

https://github.com/SubstraFoundation/substra-backend/blob/3260342014c8ef025a84a4e87436c0902f9e0506/backend/substrapp/views/model.py#L36

and

https://github.com/SubstraFoundation/substra-backend/blob/3260342014c8ef025a84a4e87436c0902f9e0506/backend/substrapp/utils.py#L193-L194


More general question: are there use cases for a /model/<tuple_key> route? I don't see it used anywhere currently.

AFAIK the model view is used by the frontend only. @jmorel could be able to provide more details.

There was a typo in the original issue: There is no /model/<tuple_key>, but there is /model/<tuple_key>/details, and this last route is used. I'll update the issue to match.

Also, these routes aren't tested in substra-tests.

And to answer your question @AurelienGasser, the /model/<tuple_key>/details route (which could become /model/<tuple_key> is used by the frontend to display all things related to a single train/aggregate task.

This is also the only way we have to retrieve all testtuples linked to a given traintuple/composite traintuple/aggregatetuple since the list of testtuples returned through /testtuples is truncated before filters are applied.