Skip to content

Fix data loading in projected-quantum-kernels tutorial - #5617

Merged
Henry Zou (henryzou50) merged 1 commit into
Qiskit:mainfrom
henryzou50:fix/pqk-data-paths
Sep 9, 2026
Merged

Fix data loading in projected-quantum-kernels tutorial#5617
Henry Zou (henryzou50) merged 1 commit into
Qiskit:mainfrom
henryzou50:fix/pqk-data-paths

Conversation

@henryzou50

Copy link
Copy Markdown
Collaborator

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:

  1. Wrong data directory. The download cell writes the CSVs into data_tutorial/pqk/, but dir_root was "./", so preprocess_data looked for the files in the working directory.
  2. Wrong projections file names. With run_experiment = False (the default), the notebook loaded projections_train.txt / projections_test.txt, which are never downloaded. The downloaded files are projections_train.csv / projections_test.csv in data_tutorial/pqk/.
  3. Malformed dataset files. The four CSVs under datasets/tutorials/pqk/ had a UTF-8 BOM, CRLF line endings, and every line of train_data.csv / test_data.csv wrapped in double quotes. pandas parsed each row as a single string column of NaNs, and np.loadtxt rejected 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_root now points at ./data_tutorial/pqk/, and the projections are loaded from the downloaded .csv files.
  • The !mkdir / !wget shell cells are replaced with urllib.request.urlretrieve, matching the approach in quantum-kernel-training and simulate-kicked-ising-tem. This works on Windows and on runners without wget.
  • The dataset CSVs are rewritten as plain UTF-8 with LF line endings and no wrapping quotes. Values are unchanged.

Testing

  • Ran the notebook locally as a script with 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, and squeaky --check pass on the notebook with the repo's docs/ruff.toml.

Note: this notebook is in the exclude group of scripts/config/notebook-testing.toml, so docs CI does not execute it. The failure was observed in the internal tutorial-tests suite.

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@qiskit-bot

Copy link
Copy Markdown
Contributor

One or more of the following people are relevant to this code:

  • @MeltemTolunay
  • @nathanearnestnoble

abbycross
abbycross previously approved these changes Sep 8, 2026

@abbycross abbycross left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@abbycross

Copy link
Copy Markdown
Collaborator

Henry Zou (@henryzou50) let me know if this is ready to merge, or go ahead and merge if it's available to you!

@abbycross

Copy link
Copy Markdown
Collaborator

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)

@henryzou50

Copy link
Copy Markdown
Collaborator Author

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.

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.
@0sophy1

Copy link
Copy Markdown
Member

Hi Abby and Henry! Once this PR is merged, I will update mine accordingly, Thanks!

@henryzou50
Henry Zou (henryzou50) added this pull request to the merge queue Sep 9, 2026
@henryzou50

Copy link
Copy Markdown
Collaborator Author

Soyoung Shin (@0sophy1) Sounds good! I added this PR to the merge queue

Merged via the queue into Qiskit:main with commit 51b432c Sep 9, 2026
4 checks passed
@henryzou50
Henry Zou (henryzou50) deleted the fix/pqk-data-paths branch September 9, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants