Skip to content

Conversation

@scymtym
Copy link
Contributor

@scymtym scymtym commented Dec 2, 2024

Running the tests locally, I got a few errors but at least some seem to be the results of issues with connections to recommendation and terminology servers.

@scymtym scymtym requested a review from glichtner December 2, 2024 09:52
@glichtner
Copy link
Member

Test fails with:
FAILED tests/recommendation/covid19_inpatient_therapy/test_rec15_prophylactic_anticoagulation.py::TestRecommendation15ProphylacticAnticoagulation_v1_2::test_recommendation_15_prophylactic_anticoagulation - AssertionError: Duplicate tasks found during task creation.

This means that at least one task gets created more than once, although it shouldn't be. The results from some tasks (specifically, criteria) are required multiple times from different (or even the same) population_intervention_pair. These criteria/tasks should be executed just once, and this assertion makes sure that each task is indeed only created once, even if required multiple times. I don't know yet where the issue comes from, but this must be fixed before merging.

@scymtym
Copy link
Contributor Author

scymtym commented Dec 4, 2024

I will update this once we are done with #242. I think, the changes in this pull request should work better then.

At least some tests call the method with bytes.
…tion

Before this change, the _root attribute was not included in the
serialized representation and thus not stored in the database. As a
result, the execution graph for a recommendation that had been
restored from the database was different from the execution graph for
a newly constructed recommendation.
Before this change, the special style in which the criterion includes
not only its attributes but also its class in the serialization data
dictionary was when serializing the Recommendation._base_criterion
attribute.

The ActivePatients criterion was compatible with that style but other
criteria were not. As a result using any criterion but ActivePatients
as the value of the _base_criterion attribute led to (de)serialization
problems.
…ctly

Before this change, the id assignment for recommendations, pi_pairs,
and criteria did interact consistently with serialization to the
database.

The new approach which this change implements uses the following
principles:

* Each of the above mentioned object types has an id attribute and
  accepts an id keyword parameter in its constructor. When no id is
  supplied, the attribute is initialized to None.

* For newly constructed objects (as opposed to objects that have been
  restored from the database) the value of the id attribute is None.

* The serialized representation of an object graph includes the id
  attributes of all objects but all id attributes must be None when the
  serialized representation is computed.

* As a consequence of the previous item: The hash value of an object
  graph includes the id attributes of all objects but all id attributes
  must be None when the hash is computed.

These principles lead to the following lifecycle for a
recommendation (the child object are processed similarly):

1. The recommendation is newly created, for example from information
   retrieved from a recommendation server. All ids are None.

2. The recommendation is registered:

   a. A hash is computed (including the None ids) and the database is
      queried. The database is queried with the computed hash.

   b.1 No match is found. The id from the matching row is assigned to
       the recommendation.

   b.2 A match is found. A preliminary representation with the
       computed hash but without the JSON representation and without
       the serialized execution graph is stored in the database. The
       result is an id for the recommendation. That id is assigned to
       the recommendation.

   c. The JSON representation and serialized execution graph are
      computed (including the assigned id) and the database row is
      updated.

3. In a subsequent run, the recommendation is restored:

   a. The database row is found based on the URL and version of the
      recommendation.

   b. The JSON representation of the object graph is loaded from the
      database row.

   c. The object graph for the recommendation and its child objects is
      deserialized from the JSON representation, including the
      previously assigned ids.
@scymtym scymtym force-pushed the criterion-db-loading-again branch from a5579d1 to 32df5a4 Compare December 10, 2024 12:52
@codecov
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

Attention: Patch coverage is 82.05128% with 7 lines in your changes missing coverage. Please review.

Project coverage is 87.59%. Comparing base (19f449d) to head (32df5a4).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
execution_engine/execution_engine.py 72.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
- Coverage   87.61%   87.59%   -0.02%     
==========================================
  Files          92       92              
  Lines        5887     5910      +23     
==========================================
+ Hits         5158     5177      +19     
- Misses        729      733       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glichtner glichtner merged commit a268ee8 into main Dec 10, 2024
1 of 3 checks passed
@glichtner glichtner deleted the criterion-db-loading-again branch December 10, 2024 13:12
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