How to use the pyhocon.ConfigFactory.parse_file function in pyhocon

To help you get started, we’ve selected a few pyhocon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github test-mile / arjuna / arjuna / core / reader / hocon.py View on Github external
def _load_config(self):
        self.set_config(ConfigFactory.parse_file(self.conf_path))
github allenai / deep_qa / deep_qa / contrib / background_search / retrieve_background.py View on Github external
def main():
    if len(sys.argv) != 2:
        print('USAGE: retrieve_background.py [param_file]')
        sys.exit(-1)

    param_file = sys.argv[1]
    params = pyhocon.ConfigFactory.parse_file(param_file)
    params = replace_none(params)

    retrieval_params = params.pop('retrieval')
    corpus_file = params.pop('corpus', None)
    question_params = params.pop('questions')
    question_file = question_params.pop('file')
    question_format = question_params.pop('format', 'sentence')
    num_neighbors = params.pop('num_neighbors', 50)
    output_file = params.pop('output', None)
    if output_file is None:
        output_file = question_file.rsplit('.', 1)[0] + ".retrieved_background.tsv"

    retrieval = VectorBasedRetrieval(retrieval_params)
    if corpus_file is not None:
        retrieval.read_background(corpus_file)
        retrieval.fit()
github mandarjoshi90 / coref / util.py View on Github external
def initialize_from_env(eval_test=False):
  if "GPU" in os.environ:
    set_gpus(int(os.environ["GPU"]))

  name = sys.argv[1]
  print("Running experiment: {}".format(name))

  if eval_test:
    config = pyhocon.ConfigFactory.parse_file("test.experiments.conf")[name]
  else:
    config = pyhocon.ConfigFactory.parse_file("experiments.conf")[name]
  config["log_dir"] = mkdirs(os.path.join(config["log_root"], name))

  print(pyhocon.HOCONConverter.convert(config, "hocon"))
  return config
github mandarjoshi90 / coref / util.py View on Github external
def initialize_from_env(eval_test=False):
  if "GPU" in os.environ:
    set_gpus(int(os.environ["GPU"]))

  name = sys.argv[1]
  print("Running experiment: {}".format(name))

  if eval_test:
    config = pyhocon.ConfigFactory.parse_file("test.experiments.conf")[name]
  else:
    config = pyhocon.ConfigFactory.parse_file("experiments.conf")[name]
  config["log_dir"] = mkdirs(os.path.join(config["log_root"], name))

  print(pyhocon.HOCONConverter.convert(config, "hocon"))
  return config
github allenai / deep_qa / src / main / python / server.py View on Github external
def serve(config_file: str):
    # read in the Typesafe-style config file and lookup the port to run on.
    params = ConfigFactory.parse_file(config_file)
    server_params = params['server']
    port = server_params['port']

    # create the server and add our RPC "servicer" to it
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

    solver_params = params['solver']
    model_type = get_choice(solver_params, 'solver_class', concrete_models.keys())
    solver_class = concrete_models[model_type]
    solver = solver_class(solver_params)
    message_pb2.add_SolverServiceServicer_to_server(SolverServer(solver), server)

    # start the server on the specified port
    server.add_insecure_port('[::]:{0}'.format(port))
    print("starting server")
    server.start()
github allenai / deep_qa / deep_qa / run.py View on Github external
Loads and returns a model.

    Parameters
    ----------
    param_path: str, required
        A json file specifying a DeepQaModel.
    model_class: DeepQaModel, optional (default=None)
        This option is useful if you have implemented a new model
        class which is not one of the ones implemented in this library.

    Returns
    -------
    A ``DeepQaModel`` instance.
    """
    logger.info("Loading model from parameter file: %s", param_path)
    param_dict = pyhocon.ConfigFactory.parse_file(param_path)
    params = Params(replace_none(param_dict))
    prepare_environment(params)

    from deep_qa.models import concrete_models
    if model_class is None:
        model_type = params.pop_choice('model_class', concrete_models.keys())
        model_class = concrete_models[model_type]
    else:
        if params.pop('model_class', None) is not None:
            raise ConfigurationError("You have specified a local model class and passed a model_class argument"
                                     "in the json specification. These options are mutually exclusive.")
    model = model_class(params)
    model.load_model()
    return model
github matanatz / pcnn / part_segmentation / train.py View on Github external
pv = SegmentationProvider()
# DEFAULT SETTINGS
parser = argparse.ArgumentParser()
parser.add_argument('--gpu', type=int, default=0, help='GPU to use [default: GPU 0]')
parser.add_argument('--batch', type=int, default=5, help='Batch Size during training [default: 32]')
parser.add_argument('--epoch', type=int, default=200, help='Epoch to run [default: 50]')
parser.add_argument('--point_num', type=int, default=2048, help='Point Number [256/512/1024/2048]')
parser.add_argument('--output_dir', type=str, default='train_results', help='Directory that stores all training logs and trained models')
parser.add_argument('--wd', type=float, default=0, help='Weight Decay [Default: 0.0]')
parser.add_argument('--config', type=str, default='pointconv_seg', help='Config file name')
parser.add_argument('--expname', type=str, default='segmentation', help='Config file name')
parser.add_argument('--hypothesis', type=str, default='', help='Config file name')

FLAGS = parser.parse_args()

conf = ConfigFactory.parse_file('../confs/{0}.conf'.format(FLAGS.config))

os.environ["CUDA_VISIBLE_DEVICES"] = '{0}'.format(FLAGS.gpu)

hdf5_data_dir = os.path.join(BASE_DIR, 'segmentation_data/hdf5_data')

# MAIN SCRIPT
point_num = FLAGS.point_num
batch_size = FLAGS.batch
timestamp = '{:%Y_%m_%d_%H_%M_%S}'.format(datetime.datetime.now())

if not os.path.exists(FLAGS.output_dir):
    os.mkdir(FLAGS.output_dir)

output_dir = os.path.join(FLAGS.output_dir,timestamp)

if not os.path.exists(output_dir):
github mandarjoshi90 / pair2vec / embeddings / util.py View on Github external
def get_config(filename, exp_name=None, save_path=None):
    config_dict = pyhocon.ConfigFactory.parse_file(filename)
    if exp_name is not None and exp_name in config_dict:
        config_dict = config_dict[exp_name]
    config = Config(**config_dict)
    if save_path is not None:
        config.save_path = save_path
    return config