IBM / pymser

A Python library to apply the Marginal Standard Error Rule (MSER) for transient regime detection and truncation on Grand Canonical Monte Carlo adsorption simulations.
BSD 3-Clause "New" or "Revised" License
19 stars 2 forks source link

Fix some `TypeError`s originating from `numpy` -> `torch` conversion #7

Open ab5424 opened 3 weeks ago

ab5424 commented 3 weeks ago

Summary

I observed some errors running the tutorial file, namely

File /rwthfs/rz/cluster/work/ab542498/venv/phonon_contribution_pymser/pymser/src/pymser/pymser.py:597, in equilibrate(input_data, LLM, batch_size, ADF_test, uncertainty, print_results)
    594 ac_time, uncorr_samples = calc_autocorrelation_time(equilibrated)
    596 # Calculates the average and standard deviation on the equilibrated data
--> 597 average, avg_uncertainty = calc_equilibrated_average(array_data,
    598                                                      t0,
    599                                                      uncertainty,
    600                                                      ac_time)
    602 # Create a dictionary with the results
    603 results_dict = {'MSE': MSEm_curve,
    604                 't0': t0,
    605                 'average': average,
   (...)
    608                 'ac_time': ac_time,
    609                 'uncorr_samples': uncorr_samples}

File /rwthfs/rz/cluster/work/ab542498/venv/phonon_contribution_pymser/pymser/src/pymser/pymser.py:301, in calc_equilibrated_average(data, eq_index, uncertainty, ac_time)
    298 # Calculate the uncorrelated Standard Error
    299 elif uncertainty == 'uSD':
    300     # Divide the equilibrated_data on uncorrelated chunks
--> 301     uncorr_batches = batch_average_data(equilibrated_data, np.ceil(ac_time).astype(int))
...
---> 87     truncated_data = data[:int(torch.floor(len(data) / batch_size) * batch_size)]
     89     # Reshape the data to create batch of size m.
     90     reshaped_data = torch.reshape(truncated_data, (-1, batch_size))

TypeError: floor(): argument 'input' (position 1) must be Tensor, not numpy.float64

and

File /rwthfs/rz/cluster/work/ab542498/venv/phonon_contribution_pymser/pymser/src/pymser/pymser.py:597, in equilibrate(input_data, LLM, batch_size, ADF_test, uncertainty, print_results)
    594 ac_time, uncorr_samples = calc_autocorrelation_time(equilibrated)
    596 # Calculates the average and standard deviation on the equilibrated data
--> 597 average, avg_uncertainty = calc_equilibrated_average(array_data,
    598                                                      t0,
    599                                                      uncertainty,
    600                                                      ac_time)
    602 # Create a dictionary with the results
    603 results_dict = {'MSE': MSEm_curve,
    604                 't0': t0,
    605                 'average': average,
   (...)
    608                 'ac_time': ac_time,
    609                 'uncorr_samples': uncorr_samples}

File /rwthfs/rz/cluster/work/ab542498/venv/phonon_contribution_pymser/pymser/src/pymser/pymser.py:301, in calc_equilibrated_average(data, eq_index, uncertainty, ac_time)
    298 # Calculate the uncorrelated Standard Error
    299 elif uncertainty == 'uSD':
    300     # Divide the equilibrated_data on uncorrelated chunks
--> 301     uncorr_batches = batch_average_data(equilibrated_data, np.ceil(ac_time).astype(int))
...
---> 90 reshaped_data = torch.reshape(truncated_data, (-1, batch_size))
     92 # Get the average of each batch
     93 averaged_batches = torch.tensor([torch.average(i) for i in reshaped_data])

TypeError: reshape(): argument 'input' (position 1) must be Tensor, not numpy.ndarray

which I think are related to commit d6b9517. I changed some of the conversion between numpy and torch and at least the pymser_tutorial.ipynb now runs fine for me.

Checklist

Related Issue(s)

Closes #8

Notes to Reviewer

...