"""Slice saved tree and save."""
import pickle

NQUBITS, NLAYERS = 25, 10

with open(f"data/tree_q{NQUBITS}_l{NLAYERS}.pkl", 'rb') as f:
    tree = pickle.load(f)

print(f"Original peak: {tree.max_size() * 16 / 1e9:.2f} GB")

tree_sliced = tree.slice_and_reconfigure(target_size=2**30)  # 2^29 = 8 GB

with open(f"data/tree_q{NQUBITS}_l{NLAYERS}_sliced.pkl", 'wb') as f:
    pickle.dump(tree_sliced, f)

print(f"Sliced peak: {tree_sliced.max_size() * 16 / 1e9:.2f} GB  Slices: {tree_sliced.multiplicity}")
