<jupyter_start><jupyter_text>QCoDeS configThe QCoDeS config module uses JSON files to store QCoDeS configuration modeled after the module structure with some high-level switches. The config file controls various options to QCoDeS such as the default path and name of the database in which your data is stored and logging level of the debug output. QCoDeS is shipped with a default configuration. As we describe below, you may overwrite these default values to customize QCoDeS for your nanoelectronics research. You may want to do something as simple as changing the default path of your database to something complex as including your own configuration variables. In this example notebook, we will explore some of the configuration variables, demonstrate how configuration values may be changed at runtime and saved to files, and explore using custom configuration values to suit your own needs.    QCoDeS loads both the defaults and the active configuration at the module import so that you can directly inspect them<jupyter_code>import qcodes as qc
qc.config.current_config<jupyter_output><empty_output><jupyter_text>The current config is build from multiple config files.The config files are read in the following order:* Package defaults* User's home directory* QCODES_CONFIG environment variable* Current working directoryMeaning that any value set in a config file in the package default is overwritten by the same value in the users home dir and so on. Note: A change in the configuration requires reimporting the package, or restarting the notebook kernel.<jupyter_code>qc.config.defaults<jupyter_output><empty_output><jupyter_text>One can inspect what the configuration options mean at runtime<jupyter_code>print(qc.config.describe('core'))<jupyter_output>controls core settings of qcodes.
Current value: {'default_fmt': 'data/{date}/#{counter}_{name}_{time}', 'register_magic': False, 'import_legacy_api': False, 'db_location': '~/experiments.db', 'db_debug': False, 'loglevel': 'WARNING', 'file_loglevel': 'INFO'}. Type: object. Default: Not defined.<jupyter_text>The default configuration is explained in more detail in the [api docs](../api/configuration/config.rstqcodes-default-configuration)  Configuring QCoDeS Defaults are the settings that are shipped with the package, which you can overwrite programmatically. A way to customize QCoDeS is to write your own JSON files, they are expected to be in the directories printed below and documented above.One will be empty because one needs to define first the environment variable in the OS. They are ordered by "weight", meaning that the last file always wins if it's overwriting any preconfigured defaults or values in the other files.Simply copy the file to the directories and you are good to go.<jupyter_code>print("\n".join([qc.config.home_file_name, qc.config.env_file_name, qc.config.cwd_file_name]))<jupyter_output>C:\Users\Jens-work\qcodesrc.json

C:\Users\Jens-work\source\repos\Qcodes\docs\examples\qcodesrc.json<jupyter_text>The easiest way to add something to the configuration is to use the provided helper:<jupyter_code>qc.config.add("base_location", "/dev/random", value_type="string", description="Location of data", default="/dev/random")<jupyter_output><empty_output><jupyter_text>This will add a `base_location` with value `/dev/random` to the current configuration, and validate it's value to be of type string, will also set the description and what one would want to have as default.The new entry is saved in the 'user' part of the configuration.<jupyter_code>print(qc.config.describe('user.base_location'))<jupyter_output>Location of data.
Current value: /dev/random. Type: string. Default: /dev/random.<jupyter_text>You can also manually update the configuration from a specific file by supplying the path of the directory as the argument of `qc.config.update_config` method as follows:<jupyter_code>qc.config.update_config(path="C:\\Users\\jenielse\\")<jupyter_output><empty_output><jupyter_text>Saving changes All the changes made to the defaults are stored, and one can then decide to save them to the desired location.<jupyter_code>help(qc.config.save_to_cwd)
help(qc.config.save_to_env)
help(qc.config.save_to_home)<jupyter_output>Help on method save_to_home in module qcodes.configuration.config:

save_to_home() -> None method of qcodes.configuration.config.Config instance
    Save config and schema to files in home dir<jupyter_text>Using custom variables in your experiment:Simply get the value you have set before with dot notation.For example:<jupyter_code>qc.config.add("base_location", "/dev/random", value_type="string", description="Location of data", default="/dev/random")

qc.config.current_config<jupyter_output><empty_output><jupyter_text>Changing core values One can change the core values at runtime, but there is no guarantee that they are going to be valid.Since user configuration shadows the default one that comes with QCoDeS, apply care when changing the values under `core` section. This section is, primarily, meant for the settings that are determined by QCoDeS core developers.<jupyter_code>qc.config.current_config.core.loglevel = 'INFO'<jupyter_output><empty_output><jupyter_text>But one can manually validate via<jupyter_code>qc.config.validate()<jupyter_output><empty_output><jupyter_text>Which will raise an exception in case of bad inputs<jupyter_code>qc.config.current_config.core.loglevel = 'YOLO'
qc.config.validate()
# NOTE that you how have a broken config!<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0733429916696849, 'fraction_numerical': 0.0, 'mean_word_length': 6.257555847568988, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '368426', 'license': 'MIT', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1488, 'n_words': 618, 'path': 'docs/examples/Configuring_QCoDeS.ipynb', 'repo_name': 'jakeogh/Qcodes', 'size': '5522'}