{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Logfile parsing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here, we provide an example concerning how to benefit from QCoDeS logs by simple analysis and visualisation." ] }, { "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\\220603-13972-qcodes.log\n" ] } ], "source": [ "%matplotlib inline\n", "import os\n", "from zipfile import ZipFile\n", "\n", "import matplotlib.pyplot as plt\n", "\n", "from qcodes.logger import log_to_dataframe, time_difference" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# put the 30MB into a zip file\n", "filepath = os.path.join(os.getcwd(), 'static', 'pythonlog.zip')\n", "with ZipFile(filepath) as z:\n", " with z.open('pythonlog.log', 'r') as f:\n", " my_log = [line.decode() for line in f]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "os.path.exists(filepath)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "logdata = log_to_dataframe(my_log, separator=' - ', columns=['time', 'module', 'function', 'loglevel', 'message'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `logdata` is, now, a nice and tidy `DataFrame` that one can further manipulate to extract more information, if needed." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", " | time | \n", "module | \n", "function | \n", "loglevel | \n", "message | \n", "
---|---|---|---|---|---|
0 | \n", "2018-05-10 16:01:50,497 | \n", "qcodes.instrument_drivers.QDev.QDac_channels | \n", "write | \n", "DEBUG | \n", "Writing to instrument qdac: wav 2 0 0 0;set 2 ... | \n", "
1 | \n", "2018-05-10 16:01:50,546 | \n", "qcodes.instrument.visa | \n", "ask_raw | \n", "DEBUG | \n", "Querying instrument SR860_120: OUTP? 2\\r\\n | \n", "
2 | \n", "2018-05-10 16:01:50,552 | \n", "qcodes.instrument.visa | \n", "ask_raw | \n", "DEBUG | \n", "Got response from instrument SR860_120: 8.9832... | \n", "
3 | \n", "2018-05-10 16:01:50,553 | \n", "qcodes.instrument.visa | \n", "ask_raw | \n", "DEBUG | \n", "Querying instrument SR860_120: SLVL?\\r\\n | \n", "
4 | \n", "2018-05-10 16:01:50,561 | \n", "qcodes.instrument.visa | \n", "ask_raw | \n", "DEBUG | \n", "Got response from instrument SR860_120: 9.9999... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
255146 | \n", "2018-05-10 17:12:03,208 | \n", "qcodes.instrument.visa | \n", "ask_raw | \n", "DEBUG | \n", "Querying instrument SR860_120: OUTP? 2\\r\\n | \n", "
255147 | \n", "2018-05-10 17:12:14,257 | \n", "qcodes.data.data_set | \n", "finalize | \n", "DEBUG | \n", "Finalising the DataSet. Writing.\\r\\n | \n", "
255148 | \n", "2018-05-10 17:12:14,258 | \n", "qcodes.data.gnuplot_format | \n", "write | \n", "DEBUG | \n", "Attempting to write the following group: qdac_... | \n", "
255149 | \n", "2018-05-10 17:12:14,259 | \n", "qcodes.data.gnuplot_format | \n", "write | \n", "DEBUG | \n", "Wrote to file from 40200 to 40201\\r\\n | \n", "
255150 | \n", "2018-05-10 17:12:14,378 | \n", "qdev_wrappers.sweep_functions | \n", "_do_measurement | \n", "ERROR | \n", "Exception in doND\\r\\n | \n", "
255151 rows × 5 columns
\n", "