def test__hyper_search(self): setup = ag.SetupHyper(search_inversion_cls=None, search_inversion_dict=None) assert setup.search_inversion_cls == af.DynestyStatic assert setup.search_inversion_dict == { "nlive": 50, "sample": "rstagger", "dlogz": 10, } setup = ag.SetupHyper( search_inversion_cls=af.DynestyDynamic, search_inversion_dict={"hello": "there"}, ) assert setup.search_inversion_cls == af.DynestyDynamic assert setup.search_inversion_dict == {"hello": "there"} setup = ag.SetupHyper(search_noise_cls=None, search_noise_dict=None) assert setup.search_noise_cls == af.DynestyStatic assert setup.search_noise_dict == {"nlive": 50, "sample": "rwalk"} setup = ag.SetupHyper( search_noise_cls=af.DynestyDynamic, search_noise_dict={"hello": "there"} ) assert setup.search_noise_cls == af.DynestyDynamic assert setup.search_noise_dict == {"hello": "there"}
def test__hyper_model_from__adds_hyper_galaxies(): model = af.Collection( galaxies=af.Collection( galaxy_0=af.Model(ag.Galaxy, redshift=0.5), galaxy_1=af.Model(ag.Galaxy, redshift=1.0, bulge=ag.lp.EllSersic), ) ) instance = model.instance_from_prior_medians() path_galaxy_tuples = [ (("galaxies", "galaxy_0"), ag.Galaxy(redshift=0.5)), (("galaxies", "galaxy_1"), ag.Galaxy(redshift=1.0)), ] hyper_galaxy_image_path_dict = { ("galaxies", "galaxy_0"): ag.Array2D.ones( shape_native=(3, 3), pixel_scales=1.0 ), ("galaxies", "galaxy_1"): ag.Array2D.full( fill_value=2.0, shape_native=(3, 3), pixel_scales=1.0 ), } result = mock.MockResult( instance=instance, path_galaxy_tuples=path_galaxy_tuples, hyper_galaxy_image_path_dict=hyper_galaxy_image_path_dict, ) setup_hyper = ag.SetupHyper() setup_hyper.hyper_galaxy_names = ["galaxy_0"] model = ag.util.model.hyper_model_from(result=result, setup_hyper=setup_hyper) assert isinstance(model.galaxies.galaxy_0, af.Model) assert model.galaxies.galaxy_0.redshift == 0.5 assert model.galaxies.galaxy_0.hyper_galaxy.cls is ag.HyperGalaxy assert model.galaxies.galaxy_1.hyper_galaxy is None setup_hyper = ag.SetupHyper() setup_hyper.hyper_galaxy_names = ["galaxy_0", "galaxy_1"] model = ag.util.model.hyper_model_from(result=result, setup_hyper=setup_hyper) assert isinstance(model.galaxies.galaxy_0, af.Model) assert model.galaxies.galaxy_0.redshift == 0.5 assert model.galaxies.galaxy_0.hyper_galaxy.cls is ag.HyperGalaxy assert isinstance(model.galaxies.galaxy_1, af.Model) assert model.galaxies.galaxy_1.redshift == 1.0 assert model.galaxies.galaxy_1.hyper_galaxy.cls is ag.HyperGalaxy
def test__hyper_search(self): setup = ag.SetupHyper(search=None) assert setup.search.config_dict_search["nlive"] == 150 assert setup.search.config_dict_search["dlogz"] == None setup = ag.SetupHyper(search=af.DynestyStatic(nlive=51)) assert setup.search.config_dict_search["nlive"] == 51 setup = ag.SetupHyper(hyper_galaxies=True, dlogz=0.5) assert setup.search.config_dict_search["dlogz"] == 0.5 with pytest.raises(exc.PipelineException): ag.SetupHyper(search=af.DynestyStatic(nlive=51), dlogz=3.0)
def test__hyper_search(self): setup = ag.SetupHyper(search_cls=None, search_dict=None) assert setup.search_cls == af.DynestyStatic assert setup.search_dict == { "nlive": 50, "sample": "rstagger", "dlogz": 10 } setup = ag.SetupHyper(search_cls=af.DynestyDynamic, search_dict={"hi": "there"}) assert setup.search_cls == af.DynestyDynamic assert setup.search_dict == {"hi": "there"}
def test__hyper_model_from(): model = af.Collection( galaxies=af.Collection( galaxy=af.Model( ag.Galaxy, redshift=0.5, pixelization=ag.pix.Rectangular, regularization=ag.reg.Constant, ), galaxy_1=af.Model(ag.Galaxy, redshift=1.0, bulge=ag.lp.EllSersic), ) ) instance = model.instance_from_prior_medians() result = mock.MockResult(instance=instance) model = ag.util.model.hyper_model_from(setup_hyper=ag.SetupHyper(), result=result) assert isinstance(model.galaxies.galaxy.pixelization, af.Model) assert isinstance(model.galaxies.galaxy.regularization, af.Model) assert model.galaxies.galaxy.pixelization.cls is ag.pix.Rectangular assert model.galaxies.galaxy.regularization.cls is ag.reg.Constant assert model.galaxies.galaxy_1.bulge.intensity == 1.0 assert model.hyper_image_sky is None assert model.hyper_background_noise is None model = ag.util.model.hyper_model_from(result=result, setup_hyper=None) assert model == None model = ag.util.model.hyper_model_from( setup_hyper=ag.SetupHyper( hyper_image_sky=ag.hyper_data.HyperImageSky, hyper_background_noise=ag.hyper_data.HyperBackgroundNoise, ), result=result, include_hyper_image_sky=True, ) assert isinstance(model.galaxies.galaxy.pixelization, af.Model) assert isinstance(model.galaxies.galaxy.regularization, af.Model) assert isinstance(model.hyper_image_sky, af.Model) assert isinstance(model.hyper_background_noise, af.Model) assert model.hyper_image_sky.cls == ag.hyper_data.HyperImageSky assert model.hyper_background_noise.cls == ag.hyper_data.HyperBackgroundNoise model = af.Collection( galaxies=af.Collection( galaxy=af.Model(ag.Galaxy, redshift=0.5), galaxy_1=af.Model(ag.Galaxy, redshift=1.0, bulge=ag.lp.EllSersic), ) ) instance = model.instance_from_prior_medians() result = mock.MockResult(instance=instance) model = ag.util.model.hyper_model_from(result=result, setup_hyper=ag.SetupHyper()) assert model == None