26/42
Part 6 of 8 · The best setLearn and do

When the fit is a sum, every member is needed if dropping the smallest breaks the fit

A scheduler that offers choices shouldn't offer atlas plus delta. Atlas alone already fits, so delta is dead weight. A set where every machine is needed is one where dropping any one of them breaks the fit:

def every_one_needed(group, need):
    return all(gpus(group) - MACHINES[name]["gpus"] < need for name in group)


needed = [group for group in fits if every_one_needed(group, 8)]
for group in sorted(needed, key=lambda g: (len(g), -gpus(g), g)):
    print(group, gpus(group))
('atlas',) 8
('birch', 'fjord') 10
('cedar', 'fjord') 10
('birch', 'cedar') 8
('delta', 'fjord') 8
('ember', 'fjord') 8
('birch', 'delta', 'ember') 8
('cedar', 'delta', 'ember') 8

When the fit is a sum, one check does it. Dropping the machine with the fewest GPUs loses the least. So if even that drop breaks the fit, every other drop does too: gpus(group) - min(MACHINES[n]["gpus"] for n in group) < need.

Of the 53 sets with at least 8 GPUs, 8 have every machine needed, and the two checks agreed on all 53. They're printed above in the order of (len(group), -gpus(group), group).

In the editor, sizes holds the GPUs of each machine in a set that fits. Write all_needed(sizes, need): the one check, whether dropping the smallest machine breaks the fit.