Fix data loading in projected-quantum-kernels tutorial - #5617
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
One or more of the following people are relevant to this code:
|
|
Henry Zou (@henryzou50) let me know if this is ready to merge, or go ahead and merge if it's available to you! |
|
Oh I just noticed that this PR from Soyoung Shin (@0sophy1) edits the same tutorial. Does the work in these two PRs need to be coordinated? Henry Zou (@henryzou50) |
|
Thanks for catching that, Abby. Yes, they overlap: #5608 fixes the same four notebook bugs I hit (wget, dir_root, the .txt projections, and the malformed CSVs), and it came first, so let's let it own the notebook changes. I'll trim this PR down to just the dataset file cleanup under datasets/tutorials/pqk/ (BOM, CRLF, and wrapping quotes). That's still useful on its own since it fixes the source files, and with the notebook change dropped the two PRs no longer touch the same files, so they can merge in either order. Soyoung Shin (@0sophy1), once the data files are clean, the sanitize cell in #5608 becomes a no-op, so you could drop it if you want the tutorial shorter, but it's harmless either way. |
3e29873 to
55f8c46
Compare
The four CSVs under datasets/tutorials/pqk/ had a UTF-8 BOM, CRLF line endings, and every line of train_data.csv and test_data.csv wrapped in double quotes. pandas read each row as a single string column of NaNs, and np.loadtxt rejected the BOM. The tutorial's stored output (14:0:15) shows the author's original data parsed correctly, so the files were mangled on export. Rewrite them as plain UTF-8 with LF line endings and no wrapping quotes. Values are unchanged. The notebook-side fixes (download path, projections file names, urllib instead of wget) are handled in Qiskit#5608.
55f8c46 to
42ea581
Compare
|
Hi Abby and Henry! Once this PR is merged, I will update mine accordingly, Thanks! |
|
Soyoung Shin (@0sophy1) Sounds good! I added this PR to the merge queue |
Summary
Fixes the projected-quantum-kernels tutorial so it runs end to end. It currently fails at the preprocessing step with
FileNotFoundError: './train_data.csv', and would fail again further down even if that were fixed.Three problems, all in the tutorial's own data handling:
data_tutorial/pqk/, butdir_rootwas"./", sopreprocess_datalooked for the files in the working directory.run_experiment = False(the default), the notebook loadedprojections_train.txt/projections_test.txt, which are never downloaded. The downloaded files areprojections_train.csv/projections_test.csvindata_tutorial/pqk/.datasets/tutorials/pqk/had a UTF-8 BOM, CRLF line endings, and every line oftrain_data.csv/test_data.csvwrapped in double quotes. pandas parsed each row as a single string column of NaNs, andnp.loadtxtrejected the BOM. The stored notebook output (14:0:15) shows the author's original data parsed correctly, so the files were mangled on export.Changes
dir_rootnow points at./data_tutorial/pqk/, and the projections are loaded from the downloaded.csvfiles.!mkdir/!wgetshell cells are replaced withurllib.request.urlretrieve, matching the approach inquantum-kernel-trainingandsimulate-kicked-ising-tem. This works on Windows and on runners withoutwget.Testing
run_experiment = False(no jobs submitted) against the fixed dataset files. Download, preprocessing, backend selection, and transpilation all succeed. The preprocessing output matches the notebook's stored output (14:0:15), and the projections load with shapes (172, 180) and (74, 180). I stopped the run during the tutorial's grid search, which is untouched by this change.ruff check,ruff format --check, andsqueaky --checkpass on the notebook with the repo'sdocs/ruff.toml.Note: this notebook is in the
excludegroup ofscripts/config/notebook-testing.toml, so docs CI does not execute it. The failure was observed in the internal tutorial-tests suite.