Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmoPower #182

Open
cmbant opened this issue Jul 26, 2024 · 6 comments
Open

CosmoPower #182

cmbant opened this issue Jul 26, 2024 · 6 comments

Comments

@cmbant
Copy link
Collaborator

cmbant commented Jul 26, 2024

For fun I tried to see if I could get cosmopower working following instructions, but did not get far- looks quite out of date? e.g. presumably data files should be linked to https://github.com/cosmopower-organization/jense_2024_emulators rather than original file, and unclear how one is supposed to use a TT+EE+TE likelihood with all the separate network files.

(As previously discussed, I guess ideally it does not need to be in SOLikeT at all if the cobaya component is included in the cosmopower package)

When I try to run the example on the CosmoPower home page I also fail with this

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 7
      4 import cosmopower as cp
      6 # load pre-trained NN model: maps cosmological parameters to CMB TT log-C_ell
----> 7 cp_nn = cp.cosmopower_NN(restore=True, 
      8                          restore_filename=r'C:\Work\Dist\git\SO\SOLikeT\soliket\cosmopower\data\CP_paper\cmb_TT_NN')
     10 # create a dict of cosmological parameters
     11 params = {'omega_b': [0.0225],
     12           'omega_cdm': [0.113],
     13           'h': [0.7],
   (...)
     16           'ln10^{10}A_s': [3.07],
     17           }

File ~\anaconda3\envs\py12\Lib\site-packages\cosmopower\cosmopower_NN.py:68, in cosmopower_NN.__init__(self, parameters, modes, parameters_mean, parameters_std, features_mean, features_std, n_hidden, restore, restore_filename, trainable, optimizer, verbose)
     66 # restore
     67 if restore is True:
---> 68     self.restore(restore_filename)
     70 # else set variables from input arguments
     71 else:
     72     # attributes
     73     self.parameters = parameters

File ~\anaconda3\envs\py12\Lib\site-packages\cosmopower\cosmopower_NN.py:285, in cosmopower_NN.restore(self, filename)
    278 # load attributes
    279 with open(filename + ".pkl", 'rb') as f:
    280     self.W_, self.b_, self.alphas_, self.betas_, \
    281     self.parameters_mean_, self.parameters_std_, \
    282     self.features_mean_, self.features_std_, \
    283     self.n_parameters, self.parameters, \
    284     self.n_modes, self.modes, \
--> 285     self.n_hidden, self.n_layers, self.architecture = pickle.load(f)

ModuleNotFoundError: No module named 'tensorflow.python.training.tracking'
Copy link
Collaborator

Which tensorflow version are you running with?

Currently, cosmopower requires:
tensorflow<2.14
tensorflow_probability<0.22

@borisbolliet
Copy link
Collaborator

see also: alessiospuriomancini/cosmopower#22

@cmbant
Copy link
Collaborator Author

cmbant commented Jul 26, 2024

I do have tensorflow 2.17. But I did do a clean install. Specifically I did

conda create -n cosmopower python=3.12 scipy matplotlib
activate cosmopower
pip install cosmopower
pip install ipykernel jupyterlab
python -m ipykernel install --user --name=cosmopower

However, running cosmopower now gives

Failed to import TF-Keras. Please note that TF-Keras is not installed by default when you install TensorFlow Probability. This is so that JAX-only users do not have to install TensorFlow or TF-Keras. To use TensorFlow Probability with TensorFlow, please install the tf-keras or tf-keras-nightly package.
This can be be done through installing the tensorflow-probability[tf] extra.

So I did
pip install tensorflow-probability[tf]
Perhaps a version-tagged version of tensorflow-probability[tf] needs to be in requirements?

@cmbant
Copy link
Collaborator Author

cmbant commented Jul 26, 2024

Converting all pkl to numpy does seem like a good idea (dpiras/cosmopower-jax#5)

@alessiospuriomancini
Copy link

This has now been fixed in commit 65fa9d6 and incorporated in the new v0.2.0 release. Note that python versions up to 3.11 are supported. python=3.12 is currently in bugfix and support for it will likely be added in alessiospuriomancini/cosmopower#28.

@cmbant
Copy link
Collaborator Author

cmbant commented Jul 29, 2024

Thanks! (btw, Anaconda's default download is now python 12)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants