Skip to content

Commit 781aa36

Browse files
authored
[SYNPY-1589] Implement "Evaluation" OOP model (#1244)
* TDD: initial proof of concept integration tests (async) * [SYNPY-1589] Implement core functionality of Evaluation OOP model (#1245) * Initialize protocol class + Evaluation dataclass * exposing Evaluation API services. dataclass updates. syntax updates. * dataclass methods are added which wrap API service functions * fixed missing imports and syntax failures * Evaluations can be imported like from synapseclient.models import Evaluation * correct ACL inputs and output types. first pass at fixing async integration tests. * fix import issues * fix type errors. api module and its functions can now be imported individually. test improvements. * add etag to prevent issues from OCC when updating an evaluation * some formatting * refactor: update and create will rely on the attributes changing in the class object itself rather than feeding it into the method. new to_synapse_request * remove principal_id param. cannot be used. adding examples to docstrings * patch all async tests * style * remove unnecessary imports * complete refactor of store/update. store is now used for updating too * add example to Evaluation dataclass * new evaluation protocol class. moved out to protocols subfolder * add synchronous integration tests * new unit tests. updated integration tests. content_source is an immutable field. style * show available access types * remove todo * get logger instance * no need for request_type param in store_evaluation_async. removing CASE 2 for handling ID of new evals. remove integration test * docstring example formatting Co-authored-by: BryanFauble <17128019+BryanFauble@users.noreply.github.com> * update examples in docstrings * the logger called in merge_dataclass_entities is now retrieved from active client * remove _async suffix from evaluation_services functions * style * updated docstrings * store -> create_or_update, updated tests * style * refactor update_acl dataclass method for user qol * give users option to remove principals from ACL * convert sync test methods to async so it calls schedule_for_cleanup fixture properly * style * if/elif -> if/else * iteratively grab the attributes instead * request_type is now a CREATE/UPDATE enum * feed query params directly into client httpx response call so it can parse params with urlencode * style * grab the logger outside of the for-loop --------- Co-authored-by: BryanFauble <17128019+BryanFauble@users.noreply.github.com> * [SYNPY-1589] Implement documentation of Evaluation OOP model (#1247) * first draft of docs * style * update tutorial to reflect new code in tutorial script. update formatting of model examples. * add more examples to API reference docs * update tutorial source code * enforce principal_id is not none * move PRINCIPAL_ID assert. update tutorial .md * Update docs/tutorials/python/evaluation.md Co-authored-by: BryanFauble <17128019+BryanFauble@users.noreply.github.com> * force uppercase * fix uppercase force * additional prereq * fix indentation. fix example * change eval names --------- Co-authored-by: BryanFauble <17128019+BryanFauble@users.noreply.github.com> * no colons. * always rely on client logger * document refresh * update sync update_acl examples * fix vulnerability in assert statement
1 parent 525e8c8 commit 781aa36

File tree

18 files changed

+4182
-20
lines changed

18 files changed

+4182
-20
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Evaluation
2+
3+
Contained within this file are experimental interfaces for working with the Synapse Python
4+
Client. Unless otherwise noted these interfaces are subject to change at any time. Use
5+
at your own risk.
6+
7+
## API reference
8+
9+
::: synapseclient.models.Evaluation
10+
options:
11+
inherited_members: true
12+
members:
13+
- store_async
14+
- get_async
15+
- delete_async
16+
- get_all_evaluations_async
17+
- get_available_evaluations_async
18+
- get_evaluations_by_project_async
19+
- get_acl_async
20+
- update_acl_async
21+
- get_permissions_async
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Evaluation
2+
3+
Contained within this file are experimental interfaces for working with the Synapse Python
4+
Client. Unless otherwise noted these interfaces are subject to change at any time. Use
5+
at your own risk.
6+
7+
## API reference
8+
9+
::: synapseclient.models.Evaluation
10+
options:
11+
inherited_members: true
12+
members:
13+
- store
14+
- get
15+
- delete
16+
- get_all_evaluations
17+
- get_available_evaluations
18+
- get_evaluations_by_project
19+
- get_acl
20+
- update_acl
21+
- get_permissions
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Evaluations
2+
An Evaluation is essentially a container that organizes and manages the submission, assessment, and scoring of data, models, or other research artifacts.
3+
It allows teams to set up challenges where participants contribute their work, and those contributions can be systematically reviewed or scored.
4+
5+
This tutorial will walk you through the basics of working with Evaluations using the Synapse Python client.
6+
7+
## Tutorial Purpose
8+
In this tutorial you will:
9+
10+
1. Create and update an Evaluation on Synapse
11+
1. Update the ACL (Access Control List) of an Evaluation on Synapse
12+
1. Retrieve and delete all Evaluations from a given Project
13+
14+
## Prerequisites
15+
* You have completed the [Project](./project.md) tutorial, or have an existing Project on Synapse to work from
16+
* You have a Synapse user or team ID to share the evaluation with
17+
18+
## 1. Create and update an Evaluation on Synapse
19+
20+
In this first part, we'll be showing you how to interact with an Evaluation object as well as introducing you to its two core functionalities `store()` and `get()`.
21+
22+
```python
23+
{!docs/tutorials/python/tutorial_scripts/evaluation.py!lines=5-46}
24+
```
25+
26+
## 2. Update the ACL of an Evaluation on Synapse
27+
28+
Like Synapse entities, Evaluations have ACLs that can be used to control who has access to your evaluations and what level of access they have. Updating the ACL of an Evaluation object is slightly different from updating other Evaluation components, because the ACL is not an attribute of the Evaluation object. Let's see an example of how this looks:
29+
30+
```python
31+
{!docs/tutorials/python/tutorial_scripts/evaluation.py!lines=54-64}
32+
```
33+
34+
You can also remove principals from an ACL by simply feeding `update_acl` an empty list for the `access_type` argument, like so:
35+
36+
```python
37+
{!docs/tutorials/python/tutorial_scripts/evaluation.py!lines=66-67}
38+
```
39+
40+
## 3. Retrieve and delete all Evaluations from a given Project
41+
42+
Now we will show how you can retrieve lists of Evaluation objects, rather than retrieving them one-by-one with `get()`. This is a powerful tool if you want to perform the same action on all the evaluations in a given project, for example, like what we're about to do here:
43+
44+
```python
45+
{!docs/tutorials/python/tutorial_scripts/evaluation.py!lines=69-75}
46+
```
47+
48+
## Source code for this tutorial
49+
50+
<details class="quote">
51+
<summary>Click to show me</summary>
52+
53+
```python
54+
{!docs/tutorials/python/tutorial_scripts/evaluation.py!}
55+
```
56+
</details>
57+
58+
## References
59+
- [Evaluation][synapseclient.models.Evaluation]
60+
- [Project][synapseclient.models.Project]
61+
- [syn.login][synapseclient.Synapse.login]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
Here is where you'll find the code for the Evaluation tutorial.
3+
"""
4+
5+
from synapseclient import Synapse
6+
from synapseclient.models import Evaluation, Project
7+
8+
syn = Synapse()
9+
syn.login()
10+
11+
# REQUIRED: Set this to the Synapse user ID or team ID you want to grant permissions to
12+
# Do NOT leave this as None - the script will not work properly
13+
PRINCIPAL_ID = None # Replace with actual user/team ID
14+
15+
# Retrieve the Project where your Evaluation will be stored
16+
project = Project(name="My uniquely named project about Alzheimer's Disease").get()
17+
project_id = project.id
18+
19+
print(f"Working within Project: {project_id}")
20+
21+
# Create a new Evaluation object
22+
evaluation = Evaluation(
23+
name="My Challenge Evaluation for Study ABC - Round 1",
24+
description="Evaluation for my data challenge",
25+
content_source=project_id,
26+
submission_instructions_message="Submit CSV files only",
27+
submission_receipt_message="Thank you for your submission!",
28+
)
29+
30+
# Create the Evaluation on Synapse
31+
evaluation.store()
32+
33+
print("Evaluation has been created with the following name and description:")
34+
print(evaluation.name)
35+
print(evaluation.description)
36+
37+
# Update the Evaluation object's name and description
38+
evaluation.name = "My Challenge Evaluation for Study XYZ - Round 1"
39+
evaluation.description = "Updated description for my evaluation"
40+
41+
# Update the Evaluation on Synapse
42+
evaluation.store()
43+
44+
print("Evaluation has been updated with the following name and description:")
45+
print(evaluation.name)
46+
print(evaluation.description)
47+
48+
# Confirm what's in Synapse matches the evaluation stored
49+
from_synapse = Evaluation(id=evaluation.id).get()
50+
51+
print("The following evaluation has been retrieved from Synapse:")
52+
print(from_synapse)
53+
54+
# Update the Evaluation's ACL on Synapse by adding a new user
55+
assert (
56+
PRINCIPAL_ID is not None
57+
), "PRINCIPAL_ID must be set to the Synapse user ID or team ID you want to grant permissions to."
58+
59+
evaluation.update_acl(principal_id=PRINCIPAL_ID, access_type=["READ", "SUBMIT"])
60+
61+
# Get the Evaluation's ACL to confirm the update
62+
acl = evaluation.get_acl()
63+
print("The following ACL has been retrieved from Synapse:")
64+
print(acl)
65+
66+
# Now let's remove the user we just added from the Evaluation's ACL
67+
evaluation.update_acl(principal_id=PRINCIPAL_ID, access_type=[])
68+
69+
# Finally let's retrieve all Evaluations stored within this project, including the one we just created
70+
evaluations_list = Evaluation.get_evaluations_by_project(project_id)
71+
72+
# Let's delete the evaluation we created for this tutorial, and any other evaluations in this project (uncomment below to enable deletion)
73+
# for evaluation_to_delete in evaluations_list:
74+
# print(f"Deleting evaluation: {evaluation_to_delete.name}")
75+
# evaluation_to_delete.delete()

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ nav:
2727
- Project: tutorials/python/project.md
2828
- Folder: tutorials/python/folder.md
2929
- File: tutorials/python/file.md
30+
- Evaluation: tutorials/python/evaluation.md
3031
- Annotation: tutorials/python/annotation.md
3132
# - Versions: tutorials/python/versions.md
3233
# - Activity/Provenance: tutorials/python/activity.md
@@ -85,6 +86,7 @@ nav:
8586
- Project: reference/experimental/sync/project.md
8687
- Folder: reference/experimental/sync/folder.md
8788
- File: reference/experimental/sync/file.md
89+
- Evaluation: reference/experimental/sync/evaluation.md
8890
- Table: reference/experimental/sync/table.md
8991
- VirtualTable: reference/experimental/sync/virtualtable.md
9092
- Dataset: reference/experimental/sync/dataset.md
@@ -104,6 +106,7 @@ nav:
104106
- Project: reference/experimental/async/project.md
105107
- Folder: reference/experimental/async/folder.md
106108
- File: reference/experimental/async/file.md
109+
- Evaluation: reference/experimental/async/evaluation.md
107110
- Table: reference/experimental/async/table.md
108111
- VirtualTable: reference/experimental/async/virtualtable.md
109112
- Dataset: reference/experimental/async/dataset.md

synapseclient/api/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@
6363
update_activity,
6464
update_entity_acl,
6565
)
66+
from .evaluation_services import (
67+
create_or_update_evaluation,
68+
delete_evaluation,
69+
get_all_evaluations,
70+
get_available_evaluations,
71+
get_evaluation,
72+
get_evaluation_acl,
73+
get_evaluation_permissions,
74+
get_evaluations_by_project,
75+
update_evaluation_acl,
76+
)
6677
from .file_services import (
6778
AddPartResponse,
6879
get_file_handle,
@@ -261,4 +272,14 @@
261272
"is_user_certified",
262273
# table_services
263274
"create_table_snapshot",
275+
# evaluation_services
276+
"create_or_update_evaluation",
277+
"get_evaluation",
278+
"get_evaluations_by_project",
279+
"get_all_evaluations",
280+
"get_available_evaluations",
281+
"delete_evaluation",
282+
"get_evaluation_acl",
283+
"update_evaluation_acl",
284+
"get_evaluation_permissions",
264285
]

0 commit comments

Comments
 (0)