Skip to content

Use list for GoogleNoiseProperties.readout_errors values#7392

Merged
pavoljuhas merged 5 commits intoquantumlib:mainfrom
pavoljuhas:noise-props-use-list-for-readout_errors
Jun 2, 2025
Merged

Use list for GoogleNoiseProperties.readout_errors values#7392
pavoljuhas merged 5 commits intoquantumlib:mainfrom
pavoljuhas:noise-props-use-list-for-readout_errors

Conversation

@pavoljuhas
Copy link
Copy Markdown
Collaborator

Problem: The values in SuperconductingQubitsNoiseProperties.readout_errors
and GoogleNoiseProperties.readout_errors dictionaries are declared as
np.ndarray in docstrings, but annotated aslist[float] in the code,
and can be set to either type. JSON serialization fails when assigned a list.

Solution: Always convert to list[float] following the type annotation.

This fixes serialization failure for GoogleNoiseProperties objects created
with noise_properties_from_calibration.

GoogleNoiseProperties from `calibration_to_noise_properties()`
cannot be serialized.  Here is a test for that failure.
Problem: The values in `SuperconductingQubitsNoiseProperties.readout_errors`
and `GoogleNoiseProperties.readout_errors` dictionary are declared as both
`list[float]` and `np.ndarray` and can be set with either type.  JSON
serialization fails when assigned list type.

Solution: Always convert to a `list[float]` type.

This fixes serialization failure for object constructed with
`noise_properties_from_calibration`.
@pavoljuhas pavoljuhas requested review from a team, verult, vtomole and wcourtney as code owners May 30, 2025 00:46
@github-actions github-actions bot added the size: M 50< lines changed <250 label May 30, 2025
@pavoljuhas pavoljuhas requested a review from dstrain115 May 30, 2025 00:46
@pavoljuhas
Copy link
Copy Markdown
Collaborator Author

Question @dstrain115 - The json_test_data/GoogleNoiseProperties.repr file expresses readout_errors as np.array-s:

readout_errors={
cirq.GridQubit(0, 0): np.array([0.004, 0.007], dtype=np.float64),
cirq.GridQubit(0, 1): np.array([0.005, 0.008], dtype=np.float64),
cirq.GridQubit(1, 0): np.array([0.006, 0.009], dtype=np.float64)
},

This passes tests because GoogleNoiseProperties.__eq__ uses np.allclose to compare readout_errors values.

Should we leave it as is or is it better to update GoogleNoiseProperties.repr?

@codecov
Copy link
Copy Markdown

codecov bot commented May 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.68%. Comparing base (123cbf8) to head (e735a43).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7392      +/-   ##
==========================================
- Coverage   98.68%   98.68%   -0.01%     
==========================================
  Files        1112     1112              
  Lines       97737    97755      +18     
==========================================
+ Hits        96454    96471      +17     
- Misses       1283     1284       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pavoljuhas pavoljuhas enabled auto-merge June 2, 2025 19:39
@pavoljuhas pavoljuhas added this pull request to the merge queue Jun 2, 2025
Merged via the queue into quantumlib:main with commit eebcfa0 Jun 2, 2025
35 checks passed
@pavoljuhas pavoljuhas deleted the noise-props-use-list-for-readout_errors branch June 2, 2025 20:49
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
…7392)

Problem: The values in
`SuperconductingQubitsNoiseProperties.readout_errors`
and `GoogleNoiseProperties.readout_errors` dictionaries are declared as
`np.ndarray` in docstrings, but annotated as`list[float]` in the code,
and can be set to either type. JSON serialization fails when assigned a
list.

Solution: Always convert to `list[float]` following the type annotation.

This fixes serialization failure for `GoogleNoiseProperties` objects
created
with `noise_properties_from_calibration`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants