In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to simplify the configuration management in Facebook open source Hydra. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Facebook Hydra is a new open source framework designed to accelerate the creation of Python applications by simplifying the implementation of common functions such as command-line parameter handling, configuration management, and logging.
Facebook develops Hydra to speed up the development of several research projects, of which the ability to respond to changing requirements is the key.
Hydra provides an innovative way to combine application configurations, allowing the composition to be changed through configuration files and the command line. This solves the challenges that may arise when modifying the configuration, such as having to maintain many slightly different copies of the configuration, or adding custom logic to override each configuration value.
One of its main goals is to reduce the boilerplate code that usually needs to be written, such as processing command-line parameters, file-based configuration, logging, and so on. Hydra also provides a pluggable architecture designed to support future extensions, such as running code seamlessly on cloud providers.
One of the mechanisms for reducing template files is to establish a convention for specifying how the application is configured. In particular, the configuration consists of multiple sources that make up the hierarchy that can be overridden from the command line. For example, if you have a configuration. The yaml configuration file contains many configuration options for your program, and you can use it seamlessly through Hydra:
Hydra.main (config_path='config.yaml') def my_app (cfg): # use cfg configuration options...
If you want to override a configuration value during a particular run, you can provide a new value to use on the command line:
$python my_app.py db.user=root db.pass=1234
Hydra also makes it easy to work with groups of optional configuration options. For example, you can have two profiles, one to connect to the MySQL database and the other to connect to the PostgreSQL database. Each time you run your program, you can choose which configuration file to use by specifying the configuration file on the command line like this:
$python my_app.py db=postgresql
$python my_app.py db=mysql db.timeout=20
Configuration files are stored in a single directory and organized hierarchically using the file system. Hydra maps the file system hierarchy through the cfg mapping passed to the application. This allows configuration options to be organized in a separate space and then combined as needed. For example, in addition to PostgreSQL and MySQL configuration files, you can also use configuration files to describe the database schema you want to use, and then decide which database / schema combination to use in a particular run at startup:
$python my_app.py db=postgresql mode = school
$python my_app.py db=mysql schema=home
Hydra uses shell tab completion to guide you through configurations and subconfigurations that can be used on the command line, so you don't need to remember all the allowed combinations. Another benefit is that Hydra will create an output directory for each run of the program and copy the runtime configuration to any output file. This is ideal when you want to run multiple experiments and track the results so that you can compare them at the end.
Finally, Hydra includes some logging capabilities designed to reduce setup costs that are fully integrated with Hydra configuration management.
Import logging
# A logger for this file
Log = logging.getLogger (_ _ name__)
@ hydra.main ()
Def my_app (_ cfg):
Log.info ("Info level message")
Log.debug ("Debug level message")
In fact, you can set the logging level to display and turn logging on and off at the file level (from the command line or through the configuration file).
$python my_app.py hydra.verbose= [_ _ main__,hydra]
As mentioned earlier, Facebook plans to leverage its pluggable architecture to develop Hydra capabilities. It can be licensed by MIT on GitHub.
On Facebook open source Hydra on how to simplify configuration management in Python programs to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.