21cmfast / 21cmFAST

Official repository for 21cmFAST: a code for generating fast simulations of the cosmological 21cm signal
MIT License
56 stars 37 forks source link

[BUG] Inconsistent user params #383

Closed JasperSolt closed 2 months ago

JasperSolt commented 2 months ago

Hi again, in troubleshooting my last issue I ran into a new one.

I'm attempting to run the following code on the v4-prep branch:

user_params = {"HII_DIM": n_voxels, "BOX_LEN": sim_volume, "USE_INTERPOLATION_TABLES":True}
flag_options = p21c.inputs.FlagOptions(
                                        USE_HALO_FIELD=True,
                                        HALO_STOCHASTICITY=True, 
                                        USE_MASS_DEPENDENT_ZETA=True
                                    )

init_box = p21c.initial_conditions(
                                user_params=user_params,
                                random_seed=random_seed
                                )

#testing halo sampler
halolist_init = p21c.determine_halo_list(redshift=6.0,
                                     init_boxes=init_box,
                                     user_params=user_params,
                                     cosmo_params=cosmo_params,
                                     flag_options=flag_options,
                                     random_seed=random_seed)

When I run this code I get the following error:

Traceback (most recent call last):
  File "/ifs/CS/replicated/home/jsolt/EoR_NN/run_21cmFAST.py", line 142, in <module>
    halolist_init = p21c.determine_halo_list(redshift=6.0,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ifs/CS/replicated/home/jsolt/EoR_NN/torchenv/lib/python3.11/site-packages/py21cmfast/wrapper.py", line 1071, in determine_halo_list
    ) = _setup_inputs(
        ^^^^^^^^^^^^^^
  File "/ifs/CS/replicated/home/jsolt/EoR_NN/torchenv/lib/python3.11/site-packages/py21cmfast/wrapper.py", line 315, in _setup_inputs
    params = _configure_inputs(list(input_params.items()), *list(input_boxes.values()))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ifs/CS/replicated/home/jsolt/EoR_NN/torchenv/lib/python3.11/site-packages/py21cmfast/wrapper.py", line 188, in _configure_inputs
    raise ValueError(
ValueError: user_params has an inconsistent ({'HII_DIM': 256, 'BOX_LEN': 1000.0, 'USE_INTERPOLATION_TABLES': True},UserParams:
    BOX_LEN                  : 1000.0
    DIM                      : 768
    HII_DIM                  : 256
    HMF                      : 1
    INTEGRATION_METHOD_ATOMIC: 1
    INTEGRATION_METHOD_HALOS : 0
    INTEGRATION_METHOD_MINI  : 1
    KEEP_3D_VELOCITIES       : False
    MINIMIZE_MEMORY          : False
    NON_CUBIC_FACTOR         : 1.0
    NO_RNG                   : False
    N_THREADS                : 1
    PERTURB_ON_HIGH_RES      : False
    POWER_SPECTRUM           : 0
    STOC_MINIMUM_Z           : None
    USE_2LPT                 : True
    USE_FFTW_WISDOM          : False
    USE_INTERPOLATION_TABLES : True
    USE_RELATIVE_VELOCITIES  : False
    ) value with InitialConditions

I'm using the same user_params for each step so I'm not sure what could be causing this.

Thanks!

Edit 1: In looking over my code I was passing in a AstroParams object into cosmo_params, which would obviously cause an issue (my bad). But not sure why the error would tell me user_params is the problem

Edit 2: Fixing the error I mentioned in Edit 1 did not resolve the issue. So this remains a bug(?)

Edit 3: removed the user_params argument from determine_halo_list and that fixed it. Seems like it doesn't like being passed both an init_box and user_params. Noted!

steven-murray commented 2 months ago

Thanks for working through this @JasperSolt. @daviesje I think this is something that should work, so we should check it out.

daviesje commented 2 months ago

This appears to be a bug with passing UserParams as a dict. _configure_inputs is called in the setup before the parameter inputs are cast into the structs https://github.com/21cmfast/21cmFAST/blob/ef480dc7328e4dea7b46203601027fb0ff9067ca/src/py21cmfast/wrapper.py#L296-L320. @steven-murray correct me if I'm wrong but I think this bug exists in master as well. I can't see a reason why we can't move those casts up above the _configure_inputs, which should fix the issue.