Code for partition function experiment