import json
import pandas as pd
partition = json.load(open(r"./buchwald_partition.json"))
for k,v in partition.items():
    sets = []
    for list in v:
        sets.append(set(list))
    #确保sets中的集合两两不相交
    for i in range(len(sets)):
        for j in range(i+1,len(sets)):
            print(k)
            print(f"i:{i},j:{j}")
            
            assert len(sets[i].intersection(sets[j])) == 0
exp = pd.read_csv(r"/mnt/petrelfs/handong/mas/data/exp/buchwald/processed.csv")
exp = exp.drop(columns=["Reactant1","Reactant2","Product","Yield"])    
for k,v in partition.items():
#确保partition中的集合的并集等于unique的长度
    union = set()
    for list in v:
        union.update(list)
    print(union)
    print(exp[k].unique())

    assert len(union) == len(exp[k].unique())

print("partition is valid")