{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Logging" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## TL;DR\n", " * There is a QCoDeS logging module: `qcodes.logger`\n", " * Call `logger.start_all_logging` at the start of every script/session to make sure all log messages get stored to the `.qcodes/logs` folder in your home directory, or set `logger.start_logging_on_import` to `True` in your `qcodesrc.json` configuration.\n", " * For debugging purposes you can log messages of an individual instrument (and see the VISA dialog).\n", " * You can obtain all logging messages in a `pandas.DataFrame` for further analysis." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Contents\n", "- [Introduction](#Introduction)\n", "- [Set up logging in QCoDeS](#Set-up-logging-in-QCoDeS)\n", " - [QCoDeS default handlers](#QCoDeS-default-handlers)\n", " - [IPython command history](#IPython-command-history)\n", "- [Temporarily elevating the logging level](#Temporarily-elevating-the-logging-level)\n", "- [Filtering log messages by instrument](#Filtering-log-messages-by-instrument)\n", "- [Capturing Pandas.DataFrame](#Capturing-Pandas.DataFrame)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction\n", "Python offers an excellent logging framework that is widely used in QCoDeS. As a user, you might be interested in reading the log messages that are generated by QCoDeS for debugging and also profiling purposes.\n", "\n", "All log records(i.e., messages and metadata) are created using a python `logging.logger` object. In QCoDeS there is a logger for every module with the same name as the module itself, i.e., you can use `logging.getLogger('qcodes.instrument.base')` for getting the logger of the QCoDeS `Instrument`. From the dots in the names of the loggers a hierarchy is defined, at the top of which is the so called *root logger* that catches all messages.\n", "The log records created in a logger are processed by the *handlers* that have been attached to this specific *logger*.\n", "The handlers can, for example, be used to output the log messages into different locations, like the console or a log file.\n", "\n", "Every logger, handler and log record has an associated level. The default levels are: `CRITICAL`, `ERROR`, `WARNING`, `INFO` and `DEBUG`. The levels determine how messages are passed: a logger passes only records that exceeds its minimal passing level to its handlers and the handlers in turn only output those messages that exceed their minimal passing level.\n", "\n", "\n", "For a more detailed description of Python logging refer to the [official manual](https://docs.python.org/3.6/library/logging.html#module-logging) (This is all well summed up [in this chart](https://docs.python.org/3.6/howto/logging.html#logging-flow))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Instrument communication loggers\n", "Not all the used loggers in QCoDeS follow the previously presented rule of naming the logger after the module. For instruments there are the following loggers:\n", " - **qcodes.instrument.base.com**:\n", " This logger logs all the communication of the `Instrument` and its descendants with the actual physical instruments, e.g., the messages generated by the `write` and `query` calls.\n", " - **qcodes.instrument.base.com.visa**:\n", " This is a sublogger that logs all the communication related messages of the `VisaInstrument` and its descendants." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set up logging in QCoDeS\n", "At the beginning of every experiment script file you should include the following lines:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Logging hadn't been started.\n", "Activating auto-logging. Current session state plus future input saved.\n", "Filename : C:\\Users\\jenielse\\.qcodes\\logs\\command_history.log\n", "Mode : append\n", "Output logging : True\n", "Raw input log : False\n", "Timestamping : True\n", "State : active\n", "Qcodes Logfile : C:\\Users\\jenielse\\.qcodes\\logs\\221107-31864-qcodes.log\n", "Activating auto-logging. Current session state plus future input saved.\n", "Filename : C:\\Users\\jenielse\\.qcodes\\logs\\command_history.log\n", "Mode : append\n", "Output logging : True\n", "Raw input log : False\n", "Timestamping : True\n", "State : active\n", "Qcodes Logfile : C:\\Users\\jenielse\\.qcodes\\logs\\221107-31864-qcodes.log\n" ] } ], "source": [ "from qcodes.logger import start_all_logging\n", "\n", "start_all_logging()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The call to `start_all_logging` does two things:\n", "1. Create handlers to output logging messages from the root logger to the console and to a log file.\n", "2. Enable logging of the IPython commands into a separate log file." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively we can configure qcodes to automatically start logging on every import of qcodes, by running the following code once. (This will persist the current configuration in `~\\qcodesrc.json`)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from qcodes import config\n", "\n", "config.logger.start_logging_on_import = \"always\"\n", "config.save_to_home()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### QCoDeS default handlers\n", "The effect of the console handler can be seen in the two printed lines with a red background below the previous code cell. Every line corresponds to a log record. The fields of the records are separated by `¦` and have the following meaning:\n", " 0. time stamp\n", " 1. logger name, here the module name\n", " 2. record log level\n", " 3. name of the function that created the log message\n", " 4. line at which the message has been issued\n", " 5. actual log message\n", "\n", "The same format is used for the file handler. By default QCoDeS logs to the file `/.qcodes/logs/qcodes.log`. To avoid endlessly long files, the files roll over at midnight and get the date appended to their name where `qcodes.log` without date always gives you the log messages of the same day.\n", "\n", "To configure the levels you want to log/handle, you need to edit the `qcodesrc.json` file in you home directory. The default values are:\n", "```\n", " \"logger\":{\n", " \"console_level\": \"WARNING\",\n", " \"file_level\": \"INFO\",\n", " \"logger_levels\":{\n", " \"pyvisa\": \"INFO\"\n", " }\n", "```\n", "While `console_level` and `file_level` describe the levels of the two default handlers described previously, `logger_levels` is a dictionary that can be used to limit the messages passed on by module level loggers. This means with these defaults, the `pyvisa` module will not log messages on a `DEBUG` level. Therefore setting the `console_level` to `DEBUG` will not show the `pyvisa` debug messages (you certainly don't want to see them as they log every single character that is passed to an instrument with an individual message). On the other hand setting the console level to warning will still suppress `pyvisa` info messages. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### IPython command history\n", "The output above that follows these logging messages comes from IPython. It tells us that all issued IPython commands will be logged to a file. The file lives in the same log directory as the python logs and is called `command_history.log`. It will not roll over.\n", "\n", "To change the command history logging directory you will need to call `start_command_history_logger` with the new path as an argument." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Temporarily elevating the logging level\n", "Sometimes you might wish to catch more than that meets to the eye. To this end, one can temporarily elevate the logging level to catch all debug messages by using a context manager. This can simply be done via:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2022-11-07 16:17:10,440 ¦ example_logger ¦ DEBUG ¦ 4053955214 ¦ ¦ 8 ¦ This message is visible as the logging level is temporarily elevated to `DEBUG`\n" ] } ], "source": [ "import logging\n", "\n", "from qcodes import logger\n", "\n", "log = logging.getLogger(\"example_logger\")\n", "\n", "log.debug(\"This message will not be visible as the logging level is set to `DEBUG`\")\n", "\n", "with logger.console_level(logging.DEBUG):\n", " log.debug(\n", " \"This message is visible as the logging level is temporarily elevated to `DEBUG`\"\n", " )\n", "\n", "log.debug(\"The level is back to what it used to be\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For other handlers than the console handler, you can do the same thing using the `handler_level` context manager." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Filtering log messages by instrument\n", "A very common use case for logging in QCoDeS is to analyze the communication with a VISA instrument. For this purpose the logger module provides a context manager to filter the logging messages by instrument.\n", "\n", "Generally one could of course simply attach a handler to the logger of `qcodes.instrument_drivers.Vendor.Type` but this would not show the messages that are generated by the visa communication in `qcodes.instrument.visa`. Additionally with the approach implemented here one can not only filter messages for a given type of instrument but also of a specific instance.\n", "\n", "To demonstrate this consider the following mock up of the AMI430 Magnet controller that consists of individual VISA instruments for each axis, here with the names `x`, `y` and `z`:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connected to: QCoDeS AMI430_simulation (serial:1337, firmware:0.0.01) in 0.06s\n", "Connected to: QCoDeS AMI430_simulation (serial:1337, firmware:0.0.01) in 0.01s\n", "Connected to: QCoDeS AMI430_simulation (serial:1337, firmware:0.0.01) in 0.00s\n" ] } ], "source": [ "import numpy as np\n", "\n", "from qcodes.instrument_drivers.american_magnetics import AMIModel430, AMIModel4303D\n", "\n", "mag_x = AMIModel430(\n", " \"x\", address=\"GPIB::1::INSTR\", pyvisa_sim_file=\"AMI430.yaml\", terminator=\"\\n\"\n", ")\n", "mag_y = AMIModel430(\n", " \"y\", address=\"GPIB::2::INSTR\", pyvisa_sim_file=\"AMI430.yaml\", terminator=\"\\n\"\n", ")\n", "mag_z = AMIModel430(\n", " \"z\", address=\"GPIB::3::INSTR\", pyvisa_sim_file=\"AMI430.yaml\", terminator=\"\\n\"\n", ")\n", "\n", "field_limit = [\n", " lambda x, y, z: x == 0 and y == 0 and z < 3,\n", " lambda x, y, z: np.linalg.norm([x, y, z]) < 2,\n", "]\n", "\n", "driver = AMIModel4303D(\"AMI430_3D\", mag_x, mag_y, mag_z, field_limit)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the above messages you can see the prefix `[()]`. To analyze the visa communication one can use `filter_instrument`:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2022-11-07 16:17:10,566 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 247 ¦ [x(AMIModel430)] Querying: STATE?\n", "2022-11-07 16:17:10,567 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 249 ¦ [x(AMIModel430)] Response: 2\n", "2022-11-07 16:17:10,569 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 247 ¦ [x(AMIModel430)] Querying: FIELD:MAG?\n", "2022-11-07 16:17:10,571 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 249 ¦ [x(AMIModel430)] Response: 0.0\n", "2022-11-07 16:17:10,574 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 247 ¦ [x(AMIModel430)] Querying: FIELD:MAG?\n", "2022-11-07 16:17:10,576 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 249 ¦ [x(AMIModel430)] Response: 0.0\n" ] } ], "source": [ "driver.cartesian((0, 0, 0))\n", "with logger.console_level(\"DEBUG\"):\n", " with logger.filter_instrument(mag_x):\n", " driver.cartesian((0, 0, 1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The output on the console shows as expected only messages from the `x` instrument. For multiple instruments pass a sequence of instruments to `filter_instrument` we write:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2022-11-07 16:17:10,608 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 247 ¦ [x(AMIModel430)] Querying: STATE?\n", "2022-11-07 16:17:10,610 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 249 ¦ [x(AMIModel430)] Response: 2\n", "2022-11-07 16:17:10,611 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 247 ¦ [y(AMIModel430)] Querying: STATE?\n", "2022-11-07 16:17:10,613 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 249 ¦ [y(AMIModel430)] Response: 2\n", "2022-11-07 16:17:10,615 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 247 ¦ [x(AMIModel430)] Querying: FIELD:MAG?\n", "2022-11-07 16:17:10,617 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 249 ¦ [x(AMIModel430)] Response: 0.0\n", "2022-11-07 16:17:10,618 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 247 ¦ [y(AMIModel430)] Querying: FIELD:MAG?\n", "2022-11-07 16:17:10,619 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 249 ¦ [y(AMIModel430)] Response: 0.0\n", "2022-11-07 16:17:10,620 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 247 ¦ [x(AMIModel430)] Querying: FIELD:MAG?\n", "2022-11-07 16:17:10,621 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 249 ¦ [x(AMIModel430)] Response: 0.0\n", "2022-11-07 16:17:10,622 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 247 ¦ [y(AMIModel430)] Querying: FIELD:MAG?\n", "2022-11-07 16:17:10,623 ¦ qcodes.instrument.instrument_base.com.visa ¦ DEBUG ¦ visa ¦ ask_raw ¦ 249 ¦ [y(AMIModel430)] Response: 0.0\n" ] } ], "source": [ "driver.cartesian((0, 0, 0))\n", "with logger.console_level(\"DEBUG\"):\n", " with logger.filter_instrument((mag_x, mag_y)):\n", " driver.cartesian((0, 0, 1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Capturing Pandas.DataFrame\n", "To process the logs, especially with the timestamps, the [pandas module](https://pandas.pydata.org/) is highly suited. With `logger.log_to_dataframe` or `logger.logfile_to_dataframe` you can convert a log(file) to a pandas `DataFrame`. See [this](logfile_parsing.ipynb) notebook for an example.\n", "\n", "You can also use a context manager to capture the logs directly into a `DataFrame`." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from qcodes.logger import capture_dataframe" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "with logger.console_level(logging.WARN):\n", " driver.cartesian((0, 0, 0))\n", " with capture_dataframe(level=\"DEBUG\") as (handler, get_dataframe):\n", " driver.cartesian((0, 0, 1))\n", " df = get_dataframe()\n", " driver.cartesian((0, 0, 2))\n", " df2 = get_dataframe() # this is the cummulative log" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
asctimenamelevelnamemodulefuncNamelinenomessage
02022-11-07 16:17:10,669qcodes.instrument.instrument_baseDEBUGAMI430_visa_adjust_child_instruments971[AMI430_3D(AMIModel4303D)] Checking whether fi...
12022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[x(AMIModel430)] Querying: STATE?
22022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[x(AMIModel430)] Response: 2
32022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[y(AMIModel430)] Querying: STATE?
42022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[y(AMIModel430)] Response: 2
52022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: STATE?
62022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 2
72022-11-07 16:17:10,670qcodes.instrument.instrument_baseDEBUGAMI430_visa_adjust_child_instruments987[AMI430_3D(AMIModel4303D)] Field values OK, pr...
82022-11-07 16:17:10,670qcodes.instrument.instrument_baseDEBUGparameter_get_manual_parameter190[AMI430_3D(AMIModel4303D)] Getting raw value o...
92022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[x(AMIModel430)] Querying: FIELD:MAG?
102022-11-07 16:17:10,671qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[x(AMIModel430)] Response: 0.0
112022-11-07 16:17:10,671qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[y(AMIModel430)] Querying: FIELD:MAG?
122022-11-07 16:17:10,671qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[y(AMIModel430)] Response: 0.0
132022-11-07 16:17:10,671qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: FIELD:MAG?
142022-11-07 16:17:10,671qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 0.0
152022-11-07 16:17:10,671qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[x(AMIModel430)] Querying: FIELD:MAG?
162022-11-07 16:17:10,671qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[x(AMIModel430)] Response: 0.0
172022-11-07 16:17:10,672qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[y(AMIModel430)] Querying: FIELD:MAG?
182022-11-07 16:17:10,672qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[y(AMIModel430)] Response: 0.0
192022-11-07 16:17:10,672qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: FIELD:MAG?
202022-11-07 16:17:10,672qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 0.0
212022-11-07 16:17:10,673qcodes.instrument.instrument_baseDEBUGparameter_get_manual_parameter190[AMI430_3D(AMIModel4303D)] Getting raw value o...
222022-11-07 16:17:10,673qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: COIL?
232022-11-07 16:17:10,673qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 2.0
242022-11-07 16:17:10,673qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: CURR:LIMIT?
252022-11-07 16:17:10,673qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 80
262022-11-07 16:17:10,673qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: QU?
272022-11-07 16:17:10,673qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 0
282022-11-07 16:17:10,673qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: PERS?
292022-11-07 16:17:10,673qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 0
302022-11-07 16:17:10,674qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: STATE?
312022-11-07 16:17:10,674qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 2
322022-11-07 16:17:10,674qcodes.instrument.instrument_base.com.visaDEBUGvisawrite_raw233[z(AMIModel430)] Writing: PAUSE
332022-11-07 16:17:10,674qcodes.instrument.instrument_base.com.visaDEBUGvisawrite_raw233[z(AMIModel430)] Writing: CONF:FIELD:TARG 1.0
342022-11-07 16:17:10,675qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: PS:INST?
352022-11-07 16:17:10,675qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 0
362022-11-07 16:17:10,675qcodes.instrument.instrument_base.com.visaDEBUGvisawrite_raw233[z(AMIModel430)] Writing: RAMP
372022-11-07 16:17:10,675qcodes.instrument.instrument_baseDEBUGAMI430_visaset_field404[z(AMIModel430)] Starting blocking ramp of z t...
382022-11-07 16:17:10,675qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: STATE?
392022-11-07 16:17:10,676qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 2
402022-11-07 16:17:10,676qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: STATE?
412022-11-07 16:17:10,676qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 2
422022-11-07 16:17:10,676qcodes.instrument.instrument_baseDEBUGAMI430_visaset_field406[z(AMIModel430)] Finished blocking ramp
\n", "
" ], "text/plain": [ " asctime name \\\n", "0 2022-11-07 16:17:10,669 qcodes.instrument.instrument_base \n", "1 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "2 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "3 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "4 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "5 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "6 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "7 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base \n", "8 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base \n", "9 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "10 2022-11-07 16:17:10,671 qcodes.instrument.instrument_base.com.visa \n", "11 2022-11-07 16:17:10,671 qcodes.instrument.instrument_base.com.visa \n", "12 2022-11-07 16:17:10,671 qcodes.instrument.instrument_base.com.visa \n", "13 2022-11-07 16:17:10,671 qcodes.instrument.instrument_base.com.visa \n", "14 2022-11-07 16:17:10,671 qcodes.instrument.instrument_base.com.visa \n", "15 2022-11-07 16:17:10,671 qcodes.instrument.instrument_base.com.visa \n", "16 2022-11-07 16:17:10,671 qcodes.instrument.instrument_base.com.visa \n", "17 2022-11-07 16:17:10,672 qcodes.instrument.instrument_base.com.visa \n", "18 2022-11-07 16:17:10,672 qcodes.instrument.instrument_base.com.visa \n", "19 2022-11-07 16:17:10,672 qcodes.instrument.instrument_base.com.visa \n", "20 2022-11-07 16:17:10,672 qcodes.instrument.instrument_base.com.visa \n", "21 2022-11-07 16:17:10,673 qcodes.instrument.instrument_base \n", "22 2022-11-07 16:17:10,673 qcodes.instrument.instrument_base.com.visa \n", "23 2022-11-07 16:17:10,673 qcodes.instrument.instrument_base.com.visa \n", "24 2022-11-07 16:17:10,673 qcodes.instrument.instrument_base.com.visa \n", "25 2022-11-07 16:17:10,673 qcodes.instrument.instrument_base.com.visa \n", "26 2022-11-07 16:17:10,673 qcodes.instrument.instrument_base.com.visa \n", "27 2022-11-07 16:17:10,673 qcodes.instrument.instrument_base.com.visa \n", "28 2022-11-07 16:17:10,673 qcodes.instrument.instrument_base.com.visa \n", "29 2022-11-07 16:17:10,673 qcodes.instrument.instrument_base.com.visa \n", "30 2022-11-07 16:17:10,674 qcodes.instrument.instrument_base.com.visa \n", "31 2022-11-07 16:17:10,674 qcodes.instrument.instrument_base.com.visa \n", "32 2022-11-07 16:17:10,674 qcodes.instrument.instrument_base.com.visa \n", "33 2022-11-07 16:17:10,674 qcodes.instrument.instrument_base.com.visa \n", "34 2022-11-07 16:17:10,675 qcodes.instrument.instrument_base.com.visa \n", "35 2022-11-07 16:17:10,675 qcodes.instrument.instrument_base.com.visa \n", "36 2022-11-07 16:17:10,675 qcodes.instrument.instrument_base.com.visa \n", "37 2022-11-07 16:17:10,675 qcodes.instrument.instrument_base \n", "38 2022-11-07 16:17:10,675 qcodes.instrument.instrument_base.com.visa \n", "39 2022-11-07 16:17:10,676 qcodes.instrument.instrument_base.com.visa \n", "40 2022-11-07 16:17:10,676 qcodes.instrument.instrument_base.com.visa \n", "41 2022-11-07 16:17:10,676 qcodes.instrument.instrument_base.com.visa \n", "42 2022-11-07 16:17:10,676 qcodes.instrument.instrument_base \n", "\n", " levelname module funcName lineno \\\n", "0 DEBUG AMI430_visa _adjust_child_instruments 971 \n", "1 DEBUG visa ask_raw 247 \n", "2 DEBUG visa ask_raw 249 \n", "3 DEBUG visa ask_raw 247 \n", "4 DEBUG visa ask_raw 249 \n", "5 DEBUG visa ask_raw 247 \n", "6 DEBUG visa ask_raw 249 \n", "7 DEBUG AMI430_visa _adjust_child_instruments 987 \n", "8 DEBUG parameter _get_manual_parameter 190 \n", "9 DEBUG visa ask_raw 247 \n", "10 DEBUG visa ask_raw 249 \n", "11 DEBUG visa ask_raw 247 \n", "12 DEBUG visa ask_raw 249 \n", "13 DEBUG visa ask_raw 247 \n", "14 DEBUG visa ask_raw 249 \n", "15 DEBUG visa ask_raw 247 \n", "16 DEBUG visa ask_raw 249 \n", "17 DEBUG visa ask_raw 247 \n", "18 DEBUG visa ask_raw 249 \n", "19 DEBUG visa ask_raw 247 \n", "20 DEBUG visa ask_raw 249 \n", "21 DEBUG parameter _get_manual_parameter 190 \n", "22 DEBUG visa ask_raw 247 \n", "23 DEBUG visa ask_raw 249 \n", "24 DEBUG visa ask_raw 247 \n", "25 DEBUG visa ask_raw 249 \n", "26 DEBUG visa ask_raw 247 \n", "27 DEBUG visa ask_raw 249 \n", "28 DEBUG visa ask_raw 247 \n", "29 DEBUG visa ask_raw 249 \n", "30 DEBUG visa ask_raw 247 \n", "31 DEBUG visa ask_raw 249 \n", "32 DEBUG visa write_raw 233 \n", "33 DEBUG visa write_raw 233 \n", "34 DEBUG visa ask_raw 247 \n", "35 DEBUG visa ask_raw 249 \n", "36 DEBUG visa write_raw 233 \n", "37 DEBUG AMI430_visa set_field 404 \n", "38 DEBUG visa ask_raw 247 \n", "39 DEBUG visa ask_raw 249 \n", "40 DEBUG visa ask_raw 247 \n", "41 DEBUG visa ask_raw 249 \n", "42 DEBUG AMI430_visa set_field 406 \n", "\n", " message \n", "0 [AMI430_3D(AMIModel4303D)] Checking whether fi... \n", "1 [x(AMIModel430)] Querying: STATE? \n", "2 [x(AMIModel430)] Response: 2 \n", "3 [y(AMIModel430)] Querying: STATE? \n", "4 [y(AMIModel430)] Response: 2 \n", "5 [z(AMIModel430)] Querying: STATE? \n", "6 [z(AMIModel430)] Response: 2 \n", "7 [AMI430_3D(AMIModel4303D)] Field values OK, pr... \n", "8 [AMI430_3D(AMIModel4303D)] Getting raw value o... \n", "9 [x(AMIModel430)] Querying: FIELD:MAG? \n", "10 [x(AMIModel430)] Response: 0.0 \n", "11 [y(AMIModel430)] Querying: FIELD:MAG? \n", "12 [y(AMIModel430)] Response: 0.0 \n", "13 [z(AMIModel430)] Querying: FIELD:MAG? \n", "14 [z(AMIModel430)] Response: 0.0 \n", "15 [x(AMIModel430)] Querying: FIELD:MAG? \n", "16 [x(AMIModel430)] Response: 0.0 \n", "17 [y(AMIModel430)] Querying: FIELD:MAG? \n", "18 [y(AMIModel430)] Response: 0.0 \n", "19 [z(AMIModel430)] Querying: FIELD:MAG? \n", "20 [z(AMIModel430)] Response: 0.0 \n", "21 [AMI430_3D(AMIModel4303D)] Getting raw value o... \n", "22 [z(AMIModel430)] Querying: COIL? \n", "23 [z(AMIModel430)] Response: 2.0 \n", "24 [z(AMIModel430)] Querying: CURR:LIMIT? \n", "25 [z(AMIModel430)] Response: 80 \n", "26 [z(AMIModel430)] Querying: QU? \n", "27 [z(AMIModel430)] Response: 0 \n", "28 [z(AMIModel430)] Querying: PERS? \n", "29 [z(AMIModel430)] Response: 0 \n", "30 [z(AMIModel430)] Querying: STATE? \n", "31 [z(AMIModel430)] Response: 2 \n", "32 [z(AMIModel430)] Writing: PAUSE \n", "33 [z(AMIModel430)] Writing: CONF:FIELD:TARG 1.0 \n", "34 [z(AMIModel430)] Querying: PS:INST? \n", "35 [z(AMIModel430)] Response: 0 \n", "36 [z(AMIModel430)] Writing: RAMP \n", "37 [z(AMIModel430)] Starting blocking ramp of z t... \n", "38 [z(AMIModel430)] Querying: STATE? \n", "39 [z(AMIModel430)] Response: 2 \n", "40 [z(AMIModel430)] Querying: STATE? \n", "41 [z(AMIModel430)] Response: 2 \n", "42 [z(AMIModel430)] Finished blocking ramp " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
asctimenamelevelnamemodulefuncNamelinenomessage
02022-11-07 16:17:10,669qcodes.instrument.instrument_baseDEBUGAMI430_visa_adjust_child_instruments971[AMI430_3D(AMIModel4303D)] Checking whether fi...
12022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[x(AMIModel430)] Querying: STATE?
22022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[x(AMIModel430)] Response: 2
32022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[y(AMIModel430)] Querying: STATE?
42022-11-07 16:17:10,670qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[y(AMIModel430)] Response: 2
........................
812022-11-07 16:17:11,216qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: STATE?
822022-11-07 16:17:11,216qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 2
832022-11-07 16:17:11,216qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[z(AMIModel430)] Querying: STATE?
842022-11-07 16:17:11,216qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[z(AMIModel430)] Response: 2
852022-11-07 16:17:11,216qcodes.instrument.instrument_baseDEBUGAMI430_visaset_field406[z(AMIModel430)] Finished blocking ramp
\n", "

86 rows × 7 columns

\n", "
" ], "text/plain": [ " asctime name \\\n", "0 2022-11-07 16:17:10,669 qcodes.instrument.instrument_base \n", "1 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "2 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "3 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", "4 2022-11-07 16:17:10,670 qcodes.instrument.instrument_base.com.visa \n", ".. ... ... \n", "81 2022-11-07 16:17:11,216 qcodes.instrument.instrument_base.com.visa \n", "82 2022-11-07 16:17:11,216 qcodes.instrument.instrument_base.com.visa \n", "83 2022-11-07 16:17:11,216 qcodes.instrument.instrument_base.com.visa \n", "84 2022-11-07 16:17:11,216 qcodes.instrument.instrument_base.com.visa \n", "85 2022-11-07 16:17:11,216 qcodes.instrument.instrument_base \n", "\n", " levelname module funcName lineno \\\n", "0 DEBUG AMI430_visa _adjust_child_instruments 971 \n", "1 DEBUG visa ask_raw 247 \n", "2 DEBUG visa ask_raw 249 \n", "3 DEBUG visa ask_raw 247 \n", "4 DEBUG visa ask_raw 249 \n", ".. ... ... ... ... \n", "81 DEBUG visa ask_raw 247 \n", "82 DEBUG visa ask_raw 249 \n", "83 DEBUG visa ask_raw 247 \n", "84 DEBUG visa ask_raw 249 \n", "85 DEBUG AMI430_visa set_field 406 \n", "\n", " message \n", "0 [AMI430_3D(AMIModel4303D)] Checking whether fi... \n", "1 [x(AMIModel430)] Querying: STATE? \n", "2 [x(AMIModel430)] Response: 2 \n", "3 [y(AMIModel430)] Querying: STATE? \n", "4 [y(AMIModel430)] Response: 2 \n", ".. ... \n", "81 [z(AMIModel430)] Querying: STATE? \n", "82 [z(AMIModel430)] Response: 2 \n", "83 [z(AMIModel430)] Querying: STATE? \n", "84 [z(AMIModel430)] Response: 2 \n", "85 [z(AMIModel430)] Finished blocking ramp \n", "\n", "[86 rows x 7 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can of course combine the context managers:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
asctimenamelevelnamemodulefuncNamelinenomessage
02022-11-07 16:17:11,302qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[x(AMIModel430)] Querying: STATE?
12022-11-07 16:17:11,302qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[x(AMIModel430)] Response: 2
22022-11-07 16:17:11,302qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[x(AMIModel430)] Querying: FIELD:MAG?
32022-11-07 16:17:11,302qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[x(AMIModel430)] Response: 0.0
42022-11-07 16:17:11,303qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw247[x(AMIModel430)] Querying: FIELD:MAG?
52022-11-07 16:17:11,303qcodes.instrument.instrument_base.com.visaDEBUGvisaask_raw249[x(AMIModel430)] Response: 0.0
\n", "
" ], "text/plain": [ " asctime name \\\n", "0 2022-11-07 16:17:11,302 qcodes.instrument.instrument_base.com.visa \n", "1 2022-11-07 16:17:11,302 qcodes.instrument.instrument_base.com.visa \n", "2 2022-11-07 16:17:11,302 qcodes.instrument.instrument_base.com.visa \n", "3 2022-11-07 16:17:11,302 qcodes.instrument.instrument_base.com.visa \n", "4 2022-11-07 16:17:11,303 qcodes.instrument.instrument_base.com.visa \n", "5 2022-11-07 16:17:11,303 qcodes.instrument.instrument_base.com.visa \n", "\n", " levelname module funcName lineno message \n", "0 DEBUG visa ask_raw 247 [x(AMIModel430)] Querying: STATE? \n", "1 DEBUG visa ask_raw 249 [x(AMIModel430)] Response: 2 \n", "2 DEBUG visa ask_raw 247 [x(AMIModel430)] Querying: FIELD:MAG? \n", "3 DEBUG visa ask_raw 249 [x(AMIModel430)] Response: 0.0 \n", "4 DEBUG visa ask_raw 247 [x(AMIModel430)] Querying: FIELD:MAG? \n", "5 DEBUG visa ask_raw 249 [x(AMIModel430)] Response: 0.0 " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "with logger.console_level(logging.WARN):\n", " driver.cartesian((0, 0, 0))\n", " with capture_dataframe(level=\"DEBUG\") as (handler, get_dataframe):\n", " with logger.filter_instrument(mag_x, handler=handler):\n", " driver.cartesian((0, 0, 1))\n", " df = get_dataframe()\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For an analysis of the timestamps please also refer to the log analysis [example notebook](logfile_parsing.ipynb)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Telemetry" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The QCoDeS Measurement Context manager, DataSaverBuilder and DoND functions are instrumented as OpenTelemetry traces. This enables users to correlate log messages with the the measurement that they were performed within. See the (OpenTelemetry)[https://opentelemetry.io/] documentation for examples of how this can be used. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.2" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }