Skip to content

Commit 764ee5f

Browse files
authored
infra: add the ruff perf plugin (#637)
1 parent 1f4d7d9 commit 764ee5f

File tree

8 files changed

+13
-24
lines changed

8 files changed

+13
-24
lines changed

examples/advanced_circuits_algorithms/Simons_Algorithm/Simons_Algorithm.ipynb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,7 @@
755755
" + str(len(new_results.keys()))\n",
756756
" + \" returned. Please rerun Simon's algorithm.\"\n",
757757
" )\n",
758-
"string_list = []\n",
759-
"\n",
760-
"for key in new_results.keys():\n",
761-
" # if key!= \"0\"*n:\n",
762-
" string_list.append([int(c) for c in key])\n",
758+
"string_list = [[int(c) for c in key] for key in new_results.keys()]\n",
763759
"\n",
764760
"print(\"The result in matrix form is :\")\n",
765761
"for a in string_list:\n",

examples/analog_hamiltonian_simulation/06_Analog_Hamiltonian_simulation_with_PennyLane.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@
6060
"# encouraged to try other values of atomic spacing!\n",
6161
"a = 6.1 # μm\n",
6262
"num_atoms = 9\n",
63-
"coords = []\n",
64-
"for k in range(num_atoms):\n",
65-
" coords.append([k * a, 0])\n",
63+
"coords = [[k * a, 0] for k in range(num_atoms)]\n",
6664
"\n",
6765
"plt.figure(figsize=(5, 1))\n",
6866
"\n",

examples/analog_hamiltonian_simulation/09_Noisy_quantum_dynamics_for_Rydberg_atom_arrays.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,7 @@
591591
" Returns:\n",
592592
" erroneous_sites (list[list[float]]): A list of 2D erroneous coordinates\n",
593593
" \"\"\"\n",
594-
" erroneous_sites = []\n",
595-
" for site in sites:\n",
596-
" erroneous_sites.append(site + site_position_error * np.random.normal(size=2))\n",
594+
" erroneous_sites = [site + site_position_error * np.random.normal(size=2) for site in sites]\n",
597595
"\n",
598596
" return erroneous_sites"
599597
]
@@ -927,7 +925,7 @@
927925
" # Finally, put values into noisy_amplitude_values\n",
928926
" for t in noisy_amplitude_times:\n",
929927
" if t1 <= t and t <= t2:\n",
930-
" noisy_amplitude_values.append(a * t**2 + b * t + c)\n",
928+
" noisy_amplitude_values.append(a * t**2 + b * t + c) # noqa: PERF401\n",
931929
"\n",
932930
" # Next apply amplitude error\n",
933931
" rabi_errors = 1 + rabi_error_rel * np.random.normal(size=len(noisy_amplitude_values))\n",

examples/braket_features/Noise_models/Noise_models_on_Rigetti.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
" 1 - data.oneQubitFidelity[1].fidelity\n",
209209
" ) # SIMULTANEOUS_RANDOMIZED_BENCHMARKING\n",
210210
" noise_model.add_noise(Depolarizing(probability=depolarizing_rate), GateCriteria(qubits=q))\n",
211-
" except:\n",
211+
" except: # noqa: PERF203\n",
212212
" pass"
213213
]
214214
},

examples/hybrid_jobs/5_Parallelize_training_for_QML/qml_script/helper_funs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ def read_csv_raw(fname):
99
data = []
1010
with open(fname) as csvfile:
1111
readCSV = csv.reader(csvfile)
12-
for row in readCSV:
13-
data.append([r for r in row])
12+
data = [[r for r in row] for row in readCSV]
1413

1514
return data
1615

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ line-length = 100
8383
lint.isort = { known-first-party = [
8484
"braket",
8585
] }
86-
lint.extend-select = ["I"]
86+
lint.extend-select = ["I", "PERF"]
8787
lint.preview = true
8888
lint.ignore = ["E722"]

test/integ_tests/braket_features/Using_The_Adjoint_Gradient_Result_Type_mocks.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ def pre_run_inject(mock_utils):
99
res1 = mock_utils.read_file("ag_results.json", __file__)
1010
res2 = mock_utils.read_file("ag_results_2.json", __file__)
1111
res3 = mock_utils.read_file("ag_results_3.json", __file__)
12-
effects = []
13-
for i in range(3):
14-
effects.append(res1)
15-
for i in range(51):
16-
effects.append(res2)
17-
for i in range(20):
18-
effects.append(res3)
12+
13+
effects = [res1 for _ in range(3)]
14+
effects.extend([res2 for _ in range(51)])
15+
effects.extend([res3 for _ in range(20)])
16+
1917
mocker.set_task_result_side_effect(effects)
2018
random.seed(42)
2119
np.random.seed(42)

test/integ_tests/test_all_notebooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
for dir_, _, files in os.walk(examples_path):
5858
for file_name in files:
5959
if file_name.endswith(".ipynb") and ".ipynb_checkpoints" not in dir_:
60-
test_notebooks.append((dir_, file_name))
60+
test_notebooks.append((dir_, file_name)) # noqa: PERF401
6161

6262

6363
def get_mock_paths(notebook_dir, notebook_file):

0 commit comments

Comments
 (0)