File size: 4,904 Bytes
b78ff28
 
 
 
 
49442cb
b78ff28
49442cb
b78ff28
 
 
 
 
 
 
 
 
49442cb
 
 
 
b78ff28
 
 
 
 
 
 
 
 
 
 
49442cb
 
 
 
 
b78ff28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49442cb
 
b78ff28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49442cb
b78ff28
 
 
 
 
 
 
 
 
 
 
49442cb
b78ff28
 
 
 
 
 
 
49442cb
 
 
 
 
 
 
 
b78ff28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49442cb
b78ff28
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""Pydantic model for a PLUG challenge submission."""

import uuid
from datetime import UTC, datetime

from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator

from plug_challenge.benchmarks import TRACKS
from utils import safeify_username


class Submission(BaseModel):
    """One competition submission: a bundle plus who sent it.

    Serialised to JSON and stored beside the uploaded bundle in the private
    dataset repo. Only the non-private fields ever reach the leaderboard.

    A PLUG submission always covers every benchmark in one bundle, so the
    benchmark breakdown lives in the scores rather than in the submission's
    identity. What does belong to the identity is the ``track``: supervised and
    unsupervised entries are ranked on separate leaderboards.

    Attributes
    ----------
    model_config
        ``protected_namespaces=()`` disables Pydantic's "model_" warning, which
        would otherwise fire on ``model_report_link``.
    submission_id : str
        Auto-generated UUID; the storage path component.
    submitted_at : datetime
        UTC timestamp of submission.
    username : str
        Hugging Face username. Required, and with ``track`` the deduplication
        key: only a user's latest submission to each track is ranked.
    track : str
        ``supervised`` (scored on the Lo-Hi test rows) or ``unsupervised``
        (scored on every row of every benchmark).
    safe_username : str
        Path-safe form of ``username``, derived automatically.
    user_alias : str
        Display name shown instead of the username for anonymous entries.
    anonymous : bool
        If True, show ``user_alias`` on the leaderboard.
    participant_name : str
        Real name — stored privately, never displayed.
    discord_username : str
        Contact handle — stored privately.
    email : str
        Contact email — stored privately.
    affiliation : str
        Institutional affiliation — stored privately.
    model_report_link : str
        URL describing the method — a report, preprint or code repository.
        Required, and displayed on the leaderboard.
    used_proprietary_data : bool
        Whether non-public training data was used. Displayed publicly.
    open_source_code : bool
        Whether the method's code is public. Displayed publicly.
    filename : str
        Original uploaded filename.
    bundle_path : str
        Path the bundle was stored at in the private repo.

    """

    model_config = ConfigDict(protected_namespaces=())

    # --- generated ---
    submission_id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    submitted_at: datetime = Field(default_factory=lambda: datetime.now(UTC))

    # --- public identity ---
    username: str
    track: str
    safe_username: str = ""
    user_alias: str = ""
    anonymous: bool = True

    # --- private contact ---
    participant_name: str = ""
    discord_username: str = ""
    email: str = ""
    affiliation: str = ""

    # --- public disclosures ---
    model_report_link: str
    used_proprietary_data: bool = False
    open_source_code: bool = False

    # --- submission ---
    filename: str = ""
    bundle_path: str = ""

    @field_validator("track")
    @classmethod
    def _known_track(cls, track: str) -> str:
        """Reject a track the challenge does not run."""
        if track not in TRACKS:
            raise ValueError(f"track must be one of {', '.join(TRACKS)}, got {track!r}")
        return track

    @model_validator(mode="after")
    def _populate_safe_username(self) -> "Submission":
        """Derive ``safe_username`` from ``username`` after construction."""
        self.safe_username = safeify_username(self.username)
        return self

    @property
    def display_name(self) -> str:
        """Name to show on the leaderboard."""
        if self.anonymous and self.user_alias:
            return self.user_alias
        return self.username

    def public_fields(self) -> dict:
        """Return the identity columns that go into a leaderboard row.

        ``username`` is the display name, so an anonymous entry never writes the
        real account name into the leaderboard file; ``safe_username`` is kept as
        the (non-displayed) deduplication and cooldown key.

        Returns
        -------
        dict
            Leaderboard identity columns for this submission.

        """
        return {
            "submission_id": self.submission_id,
            "submitted_at": self.submitted_at.isoformat(),
            "track": self.track,
            "username": self.display_name,
            "safe_username": self.safe_username,
            "anonymous": self.anonymous,
            "model_report_link": self.model_report_link,
            "used_proprietary_data": self.used_proprietary_data,
            "open_source_code": self.open_source_code,
        }