Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra: add the ruff perf plugin #637

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,7 @@
" + str(len(new_results.keys()))\n",
" + \" returned. Please rerun Simon's algorithm.\"\n",
" )\n",
"string_list = []\n",
"\n",
"for key in new_results.keys():\n",
" # if key!= \"0\"*n:\n",
" string_list.append([int(c) for c in key])\n",
"string_list = [[int(c) for c in key] for key in new_results.keys()]\n",
"\n",
"print(\"The result in matrix form is :\")\n",
"for a in string_list:\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@
"# encouraged to try other values of atomic spacing!\n",
"a = 6.1 # μm\n",
"num_atoms = 9\n",
"coords = []\n",
"for k in range(num_atoms):\n",
" coords.append([k * a, 0])\n",
"coords = [[k * a, 0] for k in range(num_atoms)]\n",
"\n",
"plt.figure(figsize=(5, 1))\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,7 @@
" Returns:\n",
" erroneous_sites (list[list[float]]): A list of 2D erroneous coordinates\n",
" \"\"\"\n",
" erroneous_sites = []\n",
" for site in sites:\n",
" erroneous_sites.append(site + site_position_error * np.random.normal(size=2))\n",
" erroneous_sites = [site + site_position_error * np.random.normal(size=2) for site in sites]\n",
"\n",
" return erroneous_sites"
]
Expand Down Expand Up @@ -927,7 +925,7 @@
" # Finally, put values into noisy_amplitude_values\n",
" for t in noisy_amplitude_times:\n",
" if t1 <= t and t <= t2:\n",
" noisy_amplitude_values.append(a * t**2 + b * t + c)\n",
" noisy_amplitude_values.append(a * t**2 + b * t + c) # noqa: PERF401\n",
"\n",
" # Next apply amplitude error\n",
" rabi_errors = 1 + rabi_error_rel * np.random.normal(size=len(noisy_amplitude_values))\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
" 1 - data.oneQubitFidelity[1].fidelity\n",
" ) # SIMULTANEOUS_RANDOMIZED_BENCHMARKING\n",
" noise_model.add_noise(Depolarizing(probability=depolarizing_rate), GateCriteria(qubits=q))\n",
" except:\n",
" except: # noqa: PERF203\n",
" pass"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def read_csv_raw(fname):
data = []
with open(fname) as csvfile:
readCSV = csv.reader(csvfile)
for row in readCSV:
data.append([r for r in row])
data = [[r for r in row] for row in readCSV]

return data

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ line-length = 100
lint.isort = { known-first-party = [
"braket",
] }
lint.extend-select = ["I"]
lint.extend-select = ["I", "PERF"]
lint.preview = true
lint.ignore = ["E722"]
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ def pre_run_inject(mock_utils):
res1 = mock_utils.read_file("ag_results.json", __file__)
res2 = mock_utils.read_file("ag_results_2.json", __file__)
res3 = mock_utils.read_file("ag_results_3.json", __file__)
effects = []
for i in range(3):
effects.append(res1)
for i in range(51):
effects.append(res2)
for i in range(20):
effects.append(res3)

effects = [res1 for _ in range(3)]
effects.extend([res2 for _ in range(51)])
effects.extend([res3 for _ in range(20)])

mocker.set_task_result_side_effect(effects)
random.seed(42)
np.random.seed(42)
Expand Down
2 changes: 1 addition & 1 deletion test/integ_tests/test_all_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
for dir_, _, files in os.walk(examples_path):
for file_name in files:
if file_name.endswith(".ipynb") and ".ipynb_checkpoints" not in dir_:
test_notebooks.append((dir_, file_name))
test_notebooks.append((dir_, file_name)) # noqa: PERF401


def get_mock_paths(notebook_dir, notebook_file):
Expand Down