Skip to content

Commit

Permalink
Merge pull request #5331 from jenshnielsen/ruff_ipynb
Browse files Browse the repository at this point in the history
Run ruff on ipynb
  • Loading branch information
jenshnielsen authored Aug 28, 2023
2 parents f13426c + 0ad010a commit 98d1f56
Show file tree
Hide file tree
Showing 61 changed files with 123 additions and 255 deletions.
15 changes: 1 addition & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,13 @@ repos:
- id: debug-statements
- id: mixed-line-ending
args: ['--fix=no']
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/akaihola/darker
rev: 1.7.2
hooks:
- id: darker
args: [-i]
additional_dependencies: [isort]
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
hooks:
- id: nbqa-pyupgrade
args: ['--py39-plus']
additional_dependencies: [pyupgrade]
- id: nbqa-isort
additional_dependencies: [isort]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.285'
hooks:
- id: ruff
types_or: [python, pyi, jupyter, toml]
4 changes: 1 addition & 3 deletions docs/examples/DataSet/Accessing-data-in-DataSet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@
"\n",
"import numpy as np\n",
"\n",
"import qcodes\n",
"from qcodes.dataset import (\n",
" Measurement,\n",
" initialise_or_create_database_at,\n",
" load_or_create_experiment,\n",
" plot_dataset,\n",
")\n",
"from qcodes.parameters import Parameter\n",
"from qcodes.station import Station"
"from qcodes.parameters import Parameter"
]
},
{
Expand Down
2 changes: 0 additions & 2 deletions docs/examples/DataSet/Benchmarking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import qcodes as qc\n",
Expand All @@ -25,7 +24,6 @@
" initialise_database,\n",
" load_or_create_experiment,\n",
" new_data_set,\n",
" new_experiment,\n",
")"
]
},
Expand Down
14 changes: 1 addition & 13 deletions docs/examples/DataSet/Cache/write_for_caching.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,11 @@
"source": [
"%matplotlib notebook\n",
"import time\n",
"from functools import partial\n",
"from time import monotonic, sleep\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import numpy.random as rd\n",
"\n",
"import qcodes as qc\n",
"from qcodes.dataset import (\n",
" Measurement,\n",
" initialise_database,\n",
" load_by_guid,\n",
" load_by_run_spec,\n",
" load_or_create_experiment,\n",
" plot_dataset,\n",
")\n",
"from qcodes.station import Station\n",
"from qcodes.dataset import Measurement, initialise_database, load_or_create_experiment\n",
"from qcodes.tests.instrument_mocks import (\n",
" DummyInstrument,\n",
" DummyInstrumentWithMeasurement,\n",
Expand Down
1 change: 0 additions & 1 deletion docs/examples/DataSet/DataSet-class-walkthrough.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"\n",
"import numpy as np\n",
"\n",
"import qcodes\n",
"from qcodes.dataset import (\n",
" Measurement,\n",
" initialise_or_create_database_at,\n",
Expand Down
11 changes: 4 additions & 7 deletions docs/examples/DataSet/Datasaver_Builder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@
"metadata": {},
"outputs": [],
"source": [
"from functools import partial\n",
"from itertools import product\n",
"from typing import *\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import qcodes as qc\n",
Expand Down Expand Up @@ -223,7 +220,7 @@
" datasets =[datasaver.dataset for datasaver in datasavers]\n",
"\n",
"plot_dataset(datasets[0])\n",
"plot_dataset(datasets[1]);"
"plot_dataset(datasets[1])"
]
},
{
Expand Down Expand Up @@ -276,7 +273,7 @@
" dond_into(datasaver, sweep2, meas1)\n",
" \n",
" dataset = datasaver.dataset\n",
"plot_dataset(dataset, marker=\".\");"
"plot_dataset(dataset, marker=\".\")"
]
},
{
Expand Down Expand Up @@ -345,7 +342,7 @@
" datasets =[datasaver.dataset for datasaver in datasavers]\n",
"\n",
"plot_dataset(datasets[0])\n",
"plot_dataset(datasets[1]);"
"plot_dataset(datasets[1])"
]
},
{
Expand Down Expand Up @@ -392,7 +389,7 @@
"\n",
" datasets =[datasaver.dataset for datasaver in datasavers]\n",
"\n",
"plot_dataset(datasets[0]);"
"plot_dataset(datasets[0])"
]
}
],
Expand Down
9 changes: 1 addition & 8 deletions docs/examples/DataSet/Dataset_Performance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@
"import numpy as np\n",
"\n",
"import qcodes as qc\n",
"from qcodes.dataset import (\n",
" Measurement,\n",
" initialise_database,\n",
" load_last_experiment,\n",
" load_or_create_experiment,\n",
" new_experiment,\n",
")\n",
"from qcodes.dataset.experiment_container import Experiment\n",
"from qcodes.dataset import Measurement, initialise_database, load_or_create_experiment\n",
"from qcodes.parameters import ManualParameter"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@
"import shutil\n",
"from pathlib import Path\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"import qcodes as qc\n",
"import qcodes.logger\n",
Expand Down
18 changes: 3 additions & 15 deletions docs/examples/DataSet/InMemoryDataSet.ipynb

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions docs/examples/DataSet/Offline Plotting Tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"from typing import Any, Dict, List, Tuple\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import qcodes as qc\n",
"from qcodes.dataset import (\n",
" Measurement,\n",
" initialise_database,\n",
" load_or_create_experiment,\n",
" new_experiment,\n",
" plot_dataset,\n",
")\n",
"from qcodes.parameters import Parameter"
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/DataSet/Paramtypes explained.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@
"from qcodes.dataset import (\n",
" Measurement,\n",
" initialise_or_create_database_at,\n",
" load_by_id,\n",
" load_or_create_experiment,\n",
")\n",
"from qcodes.parameters import ArrayParameter, Parameter\n",
"from qcodes.parameters import ArrayParameter\n",
"from qcodes.tests.instrument_mocks import DummyInstrument"
]
},
Expand Down

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/examples/DataSet/The-Experiment-Container.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"source": [
"import os\n",
"\n",
"import qcodes as qc\n",
"from qcodes.dataset import (\n",
" connect,\n",
" experiments,\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/DataSet/Threaded data acquisition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"\n",
"from qcodes.dataset import (\n",
" Measurement,\n",
" ThreadPoolParamsCaller,\n",
" do1d,\n",
" initialise_database,\n",
" load_or_create_experiment,\n",
Expand All @@ -64,8 +65,7 @@
" DummyInstrument,\n",
" DummyInstrumentWithMeasurement,\n",
")\n",
"from qcodes.utils.threading import ThreadPoolParamsCaller, call_params_threaded\n",
"from qcodes.validators import Numbers"
"from qcodes.validators import Numbers\n"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"\n",
"import qcodes.logger\n",
"from qcodes.dataset import (\n",
" ArraySweep,\n",
" LinSweep,\n",
" LogSweep,\n",
" Measurement,\n",
Expand Down
1 change: 0 additions & 1 deletion docs/examples/DataSet/Working with snapshots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"import json # for converting JSON data into python 'dict'\n",
"from pprint import pprint # for pretty-printing python variables like 'dict'\n",
"\n",
"import qcodes\n",
"from qcodes.dataset import Measurement, initialise_database, load_or_create_experiment\n",
"from qcodes.parameters import Parameter\n",
"from qcodes.station import Station\n",
Expand Down
4 changes: 0 additions & 4 deletions docs/examples/DataSet/import-data-from-legacy-dat-files.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"\n",
"import qcodes as qc\n",
"from qcodes.dataset import (\n",
" Measurement,\n",
" import_dat_file,\n",
" initialise_database,\n",
" load_by_id,\n",
" load_or_create_experiment,\n",
" plot_by_id,\n",
")"
Expand Down
1 change: 0 additions & 1 deletion docs/examples/DataSet/subscriber json exporter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"outputs": [],
"source": [
"import copy\n",
"import json\n",
"import logging\n",
"\n",
"import numpy as np"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
" self.sweep_start.source = start_parameter\n",
" self.sweep_stop.source = stop_parameter\n",
" self.setpoints.unit = start_parameter.unit\n",
" if label != None:\n",
" if label is not None:\n",
" self.setpoints.label = label\n",
"\n",
"\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/Parameters/Parameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@
"source": [
"from typing import Optional\n",
"\n",
"import numpy as np\n",
"\n",
"from qcodes.instrument.base import InstrumentBase\n",
"from qcodes.parameters import ArrayParameter, ManualParameter, MultiParameter, Parameter\n",
"from qcodes.parameters import Parameter\n",
"from qcodes.tests.instrument_mocks import DummyInstrument\n",
"from qcodes.utils import validators"
]
Expand Down
2 changes: 0 additions & 2 deletions docs/examples/Station.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
"source": [
"# Useful imports:\n",
"\n",
"from pprint import pprint # for pretty-printing python variables like 'dict'\n",
"\n",
"import qcodes\n",
"from qcodes.instrument import Parameter\n",
"from qcodes.station import Station\n",
"from qcodes.tests.instrument_mocks import DummyInstrument"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"import time\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from qcodes.dataset import Measurement, plot_dataset\n",
"from qcodes.instrument_drivers.Keithley import Keithley7510\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"metadata": {},
"outputs": [],
"source": [
"import qcodes as qc\n",
"from qcodes.station import Station"
]
},
Expand Down
22 changes: 13 additions & 9 deletions docs/examples/driver_examples/Qcodes example with AMI430.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@
"plt.show()\n",
"slope, offset = np.polyfit(t_setting, t_actual, 1)\n",
"print(\n",
" \"slope = {}. A value close to one means the correct ramp times are used\".format(\n",
" slope\n",
" )\n",
" f\"slope = {slope}. A value close to one means the correct ramp times are used\"\n",
")\n",
"print(\n",
" \"offset = {}. An offset indicates that there is a fixed delay is added to a ramp request\".format(\n",
Expand Down Expand Up @@ -254,13 +252,16 @@
},
"outputs": [],
"source": [
"def field_is_along_z_and_less_that_3_t(x, y, z):\n",
" # We can have higher field along the z-axis if x and y are zero.\n",
" return x == 0 and y == 0 and z < 3\n",
"def field_is_less_than_2_t(x, y, z):\n",
" return np.linalg.norm([x, y, z]) < 2\n",
"# Lets test the 3D driver now.\n",
"field_limit = (\n",
" [ # If any of the field limit functions are satisfied we are in the safe zone.\n",
" lambda x, y, z: x == 0\n",
" and y == 0\n",
" and z < 3, # We can have higher field along the z-axis if x and y are zero.\n",
" lambda x, y, z: np.linalg.norm([x, y, z]) < 2,\n",
" field_is_along_z_and_less_that_3_t,\n",
" field_is_less_than_2_t,\n",
" ]\n",
")\n",
"\n",
Expand Down Expand Up @@ -428,7 +429,7 @@
"try:\n",
" i3d.cartesian([2.1, 0, 0])\n",
" print(\"something went wrong... we should not be able to do this :-(\")\n",
"except:\n",
"except Exception:\n",
" print(\"error successfully raised. The driver does not let you do stupid stuff\")"
]
},
Expand Down Expand Up @@ -548,6 +549,9 @@
"source": [
"i3d.ramp_mode(\"simultaneous\")\n",
"i3d.vector_ramp_rate(0.05) # requires all axes to have same ramp rate units!!!\n",
"x = 0\n",
"y = 0\n",
"z = 0\n",
"i3d.cartesian((x, y, z)) # or any other parameter call that initiates a ramp"
]
},
Expand Down Expand Up @@ -741,7 +745,7 @@
"\n",
"import xarray as xr\n",
"\n",
"from qcodes.dataset import LinSweep, do2d, dond, load_or_create_experiment\n",
"from qcodes.dataset import LinSweep, dond, load_or_create_experiment\n",
"from qcodes.parameters import ElapsedTimeParameter\n",
"from qcodes.tests.instrument_mocks import (\n",
" DummyInstrument,\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@
"outputs": [],
"source": [
"%matplotlib nbagg\n",
"import os\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from qcodes.dataset import Measurement, load_or_create_experiment, plot_dataset\n",
Expand Down
Loading

0 comments on commit 98d1f56

Please sign in to comment.