deepskies / deeplenstronomy

A pipeline for versatile strong lens sample simulations
MIT License
26 stars 7 forks source link

Unbound local error in `make_dataset` #120

Closed musoke closed 1 year ago

musoke commented 1 year ago

I have found that it is possible to generate an unbound local error in deeplenstronomy.deeplenstronomy.make_dataset by passing in a configuration of an unexpected type.

In particular, if config is a dict and dataset has its default value, then parser is not initialized in this section https://github.com/deepskies/deeplenstronomy/blob/00abf490c362e2e8e948924d2fad84d3ce856912/deeplenstronomy/deeplenstronomy.py#L298-L319

MWE:

import deeplenstronomy.deeplenstronomy as dl

# incomplete dict for brevity, but the result is the same even if all parameters are given
config = {'DATASET': {'NAME': 'Lens',
  'PARAMETERS': {'SIZE': 5000, 'OUTDIR': 'ExampleDataset', 'SEED': 1}},
 'COSMOLOGY': {'PARAMETERS': {'H0': 70.0, 'Om0': 0.3}},}
dl.make_dataset(config)

output

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[3], line 1
----> 1 dl.make_dataset(config)

File ~/deeplenstronomy/deeplenstronomy/deeplenstronomy.py:319, in make_dataset(config, dataset, save_to_disk, store_in_memory, verbose, store_sample, image_file_format, survey, return_planes, skip_image_generation, solve_lens_equation)
    316     dataset.config_dict = parser.config_dict
    318 # store parser
--> 319 dataset.parser = parser
    321 # Store top-level dataset info
    322 dataset.name = dataset.config_dict['DATASET']['NAME']

UnboundLocalError: local variable 'parser' referenced before assignment
Jasonpoh commented 1 year ago

If I'm understanding this right, you'd like to be able to pass a dictionary instead of a yaml file in the configuration.

Right now, I don't think that feature is supported. Out of curiosity, is there a reason you'd like to do this instead of working directly with the yaml file?

musoke commented 1 year ago

Yes, I was attempting to pass in a dict containing a configuration to work around https://github.com/deepskies/deeplenstronomy/issues/117

As it is, the doc string claims that this is possible: https://github.com/deepskies/deeplenstronomy/blob/00abf490c362e2e8e948924d2fad84d3ce856912/deeplenstronomy/deeplenstronomy.py#L275 I suspect that this is only meant to be used with the regenerate method you mentioned in the other issue?

AeRabelais commented 1 year ago

The config item in deeplenstronomy currently only supports taking a yaml file path, rather than a dictionary. Not really enough requests to work on this added feature right now. Docstrings will be changed to present input more accurately