def read_config(self, fname): config = cfg() config.read(fname) # Convert config to a dict res = {s: dict(config.items(s)) for s in config.sections()} if "outdir" not in res["IO"]: res["IO"]["outdir"] = "" if "covar_data" not in res["cosmo_paramsParams"]: res["cosmo_paramsParams"]["covar_data"] = "" # Run Options self.quantity = res["RunOptions"].pop("quantity") self.xval = res["RunOptions"].pop("xval") self.framework = res["RunOptions"].pop("framework") self.relax = bool(res["RunOptions"].pop("relax")) self.nthreads = int(res["RunOptions"].pop("nthreads")) # Derived params and quantities dparams = json.loads(res["RunOptions"].pop("der_params")) dquants = json.loads(res["RunOptions"].pop("der_quants")) self.n_dparams = len(dparams) self.blobs = dparams + dquants # Fit-options self.fit_type = res["FitOptions"].pop("fit_type") # MCMC-specific self.nwalkers = int(res["MCMC"].pop("nwalkers")) self.nsamples = int(res["MCMC"].pop("nsamples")) self.burnin = json.loads(res["MCMC"].pop("burnin")) # Downhill-specific self.downhill_kwargs = { k: json.loads(v) for k, v in list(res["Downhill"].items()) } del res["Downhill"] # IO-specific self.outdir = res["IO"].pop("outdir", None) self.chunks = int(res["IO"].pop("chunks")) # Data-specific self.data_file = res["Data"].pop("data_file") self.cov_file = res["Data"].pop("cov_file", None) # Model-specific self.model = res.pop("Model") self.model_pickle = self.model.pop("model_file", None) for k in self.model: self.model[k] = json.loads(self.model[k]) self.constraints = { k: json.loads(v) for k, v in list(res["Constraints"].items()) } return {k: res.pop(k) for k in list(res.keys()) if k.endswith("Params")}
def read_config(self, fname): config = cfg() config.read(fname) # Convert config to a dict res = {s: dict(config.items(s)) for s in config.sections()} if "outdir" not in res["IO"]: res["IO"]["outdir"] = "" if "covar_data" not in res["cosmo_paramsParams"]: res["cosmo_paramsParams"]['covar_data'] = '' # Run Options self.quantity = res["RunOptions"].pop("quantity") self.xval = res["RunOptions"].pop("xval") self.framework = res["RunOptions"].pop("framework") self.relax = bool(res["RunOptions"].pop("relax")) self.nthreads = int(res["RunOptions"].pop("nthreads")) # Derived params and quantities dparams = json.loads(res["RunOptions"].pop("der_params")) dquants = json.loads(res["RunOptions"].pop("der_quants")) self.n_dparams = len(dparams) self.blobs = dparams + dquants # Fit-options self.fit_type = res['FitOptions'].pop("fit_type") # MCMC-specific self.nwalkers = int(res["MCMC"].pop("nwalkers")) self.nsamples = int(res["MCMC"].pop("nsamples")) self.burnin = json.loads(res["MCMC"].pop("burnin")) # Downhill-specific self.downhill_kwargs = {k: json.loads(v) for k, v in list(res['Downhill'].items())} del res["Downhill"] # IO-specific self.outdir = res["IO"].pop("outdir", None) self.chunks = int(res["IO"].pop("chunks")) # Data-specific self.data_file = res["Data"].pop("data_file") self.cov_file = res["Data"].pop("cov_file", None) # Model-specific self.model = res.pop("Model") self.model_pickle = self.model.pop("model_file", None) for k in self.model: try: self.model[k] = json.loads(self.model[k]) except: pass self.constraints = {k: json.loads(v) for k, v in list(res["Constraints"].items())} param_dict = {k: res.pop(k) for k in list(res.keys()) if k.endswith("Params")} return param_dict
VerticalFlip, HorizontalFlip, OneOf, CLAHE, Normalize, RandomBrightnessContrast, Cutout, RandomGamma, ShiftScaleRotate, GaussNoise, Blur, MotionBlur, GaussianBlur, ) dr_config = cfg() dr_config.read('dr_config.ini') random_id = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(10)) params = dr_config['params'] # for k, v in config['params'].items():print(k,v) n_fold = int(params['n_fold']) fold = int(params['fold']) SEED = int(params['SEED']) batch_size = int(params['batch_size']) sz = int(params['sz']) learning_rate = float(params['learning_rate']) patience = int(params['patience']) accum_step = int(params['accum_step']) num_class = int(params['num_class'])
with tempf("w+", dir=codepath, suffix=".abe") as codef, tempf("w+", dir=codepath, suffix=".txt") as inpf: codef.write(code) inpf.write(data) codef.flush() inpf.flush() # If it fails, bubbles up TimeoutError + CalledProcessError codef.seek(0) output = subprocess.run( f'osabie "{codef.name}" < "{inpf.name}"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout, shell=True, encoding="UTF-8", ) return output.stdout if __name__ == "__main__": if not bot_key: cf = cfg() cf.read("key.cfg") bot_key = cf["DEFAULT"]["key"] try: rosy.run(bot_key) except KeyboardInterrupt: print("Received exit, exiting")