bugger.
All challenges/Pythonmediumgsoc-ml4sci-event-split-v1
THE INVESTIGATION

The collision event in both datasets

Particle rows from one simulated event leak into training and test data when a row budget cuts through their shared identity.

MLML4SCIData leakage

What’s going wrong

Original ML practice for ML4SCI contribution preparation; not an upstream bug reproduction. This independent teaching scenario uses the scientific event-analysis setting of ML4SCI projects. It is not an official selection task.

A dataset contains several particle rows for each collision event. The current splitter takes the first train_limit rows, so related particles can appear in both datasets. Repair split_events so every complete event belongs to exactly one subset.

Input is {"rows":[{"run":"run-1","event":"event-7"},...],"train_limit":2}. An event is identified by the exact pair (run, event), not either field alone. All occurrences of that pair belong together even when noncontiguous. First count every event across the complete rows array. Consider event groups in order of their first occurrence. Place the whole group in training only if its row count fits the remaining train_limit; subtract its size when selected. Otherwise place the whole group in test and continue considering later groups. Do not split a group or revisit a rejected group. Unused training capacity is allowed.

Print {"train":[...],"test":[...]} containing the zero-based original row indices in each subset, both in original input order. Every input index must appear exactly once. The input has 0 to 100 rows, train_limit is an integer from 0 through the number of rows, and run/event are nonempty case-sensitive ASCII strings of at most 32 characters. Colons and other separators are valid identifier characters. Inputs satisfy these bounds. The output indices select the original particle rows; no feature arrays or random split are modeled.

Expected behavior

Keep each complete (run, event) group in a single subset, choose training groups with the specified first-seen greedy budget, and preserve source row order within each output list.

Reproduction

01 Noncontiguous particles share one event
{"rows":[{"run":"r1","event":"e1"},{"run":"r1","event":"e2"},{"run":"r1","event":"e1"}],"train_limit":2}
{"train":[0,2],"test":[1]}
02 Independent events keep an ordinary split
{"rows":[{"run":"r1","event":"a"},{"run":"r1","event":"b"},{"run":"r1","event":"c"}],"train_limit":2}
{"train":[0,1],"test":[2]}
03 An oversized first event leaves room for later groups
{"rows":[{"run":"r","event":"a"},{"run":"r","event":"a"},{"run":"r","event":"b"},{"run":"r","event":"a"},{"run":"r","event":"c"}],"train_limit":2}
{"train":[2,4],"test":[0,1,3]}

Before you begin

  • Dictionary insertion order
  • Composite keys
  • Training and test separation

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.