AttributeError when optimizing purity of reduced density matrix

See these: