lesgourg / class_public

Public repository of the Cosmic Linear Anisotropy Solving System (master for the most recent version of the standard code; GW_CLASS to include Cosmic Gravitational Wave Background anisotropies; classnet branch for acceleration with neutral networks; ExoCLASS branch for exotic energy injection; class_matter branch for FFTlog)
225 stars 282 forks source link

Syntax Error in Example Notebooks #379

Open kabeleh opened 3 years ago

kabeleh commented 3 years ago

I just set-up everything on my Arch Linux machine and now I'm going through some of the more recent slides to better understand what is possible with class. Thank you very much for the extensive and clear documentation! I just went through the example notebooks in Jupyter. I could not run the notebooks as they were; the errors might just arise because of different conventions, which is not supported out-of-the-box by JupyterLab and python3. So far I found:

  1. warmup.ipynb -- In[3]: throws
    
    <ipython-input-3-0e756d06e6d4> in <module>
      2 cls = LambdaCDM.lensed_cl(2500)
      3 # To check the format of cls
    ----> 4 cls.viewkeys()

AttributeError: 'dict' object has no attribute 'viewkeys'

2. varying_pann.ipyn
-- `In[3] `has a print line that should read `print( ' * Compute with %s=%e'%(var_name,var))`, but the parentheses are missing.
3. varying_neff.ipyn
-- Again missing parentheses in `print( ' * Compute with %s=%e, %s=%e, %s=%e'% 'N_ur',N_ur,'omega_cdm',omega_cdm,'h',h))`
4. neutrinohierarchy.ipynb
-- `In[4]` has two print commands with missing parentheses: `print('NH:',m1,m2,m3,m1+m2+m3)` and `print('IH:',m1,m2,m3,m1+m2+m3)`
-- `Out[5]: <matplotlib.legend.Legend at 0x7f4e2a236d60>` shows a figure, but `plt.savefig('neutrinohierarchy.pdf')` creates an empty PDF-file and returns `<Figure size 432x288 with 0 Axes>`. This can be resolved e.g. by adding `fig1 = plt.gcf()` to `In[5]` and changing `In[6]` to `fig1.savefig('neutrinohierarchy.pdf')`
5. cl_ST.ipynb
-- Again, the figure is not saved. Same solution.
6. cltt_terms.ipynb
-- Again, the figure is not saved. Same solution.
7. distances.ipynb
-- `In[4]` is missing the parenthesis in both print commands.
-- `In[5]` throws 
```---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-7923c07e66ea> in <module>
      2 baLCDM = LCDM.get_background()
      3 baCDM = CDM.get_background()
----> 4 baCDM.viewkeys()

AttributeError: 'dict' object has no attribute 'viewkeys'

-- And has again the issue with saving the figure.

  1. thermo.ipynb -- In[3] is missing the parenthesis for the print command and inside the print command viewkeys is used, but 'dict' object has no attribute 'viewkeys' -- At the end, an empty figure is saved; same solution as above.

  2. one_time.ipynb -- viewkeys() is used, but unknown. -- This time, saving of the figure works. :)

  3. one_k.ipynb -- parentheses in the print commands and viewkeys() used

ThomasTram commented 3 years ago

Hi

These are old Python2 notebooks that has not been updated. You can try out these notebooks instead: https://github.com/ThomasTram/iCLASS Or you can fix the mistakes. For instance, use .keys() instead of viewkeys().

Cheers, Thomas