Skip to content

Fix EngineProgram.get_circuit(_async) empty code detection#7850

Merged
maffoo merged 2 commits intomainfrom
u/maffoo/engine-get-circuit
Jan 22, 2026
Merged

Fix EngineProgram.get_circuit(_async) empty code detection#7850
maffoo merged 2 commits intomainfrom
u/maffoo/engine-get-circuit

Conversation

@maffoo
Copy link
Copy Markdown
Contributor

@maffoo maffoo commented Jan 22, 2026

No description provided.

@github-actions github-actions bot added the Size: XS <10 lines changed label Jan 22, 2026
@maffoo maffoo force-pushed the u/maffoo/engine-get-circuit branch from 706ffe9 to b68f25f Compare January 22, 2026 20:00
if self._program is None or self._program.code is None:
# The code field is an any_pb2.Any and is always set. But if the program has not
# been fetched this field may be empty, which we can see by checking the type_url.
if self._program is None or not self._program.code or not self._program.code.type_url:
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.

Should it be at the second alternative or not self._program.code.value?

The bool(any_pb2.Any()) is True so the middle expression is effectively or False or ...

Also can we add a test that would cover the fixed failure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is mostly defense in depth because I didn't want to rely on the code attribute being set. As for whether we check type_url or value I think either is probably ok. I don't know if valid proto messages can ever have an empty byte representation, but I presume not? Do you have a particular reason to prefer value over type_url?

Copy link
Copy Markdown
Collaborator

@pavoljuhas pavoljuhas Jan 22, 2026

Choose a reason for hiding this comment

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

If we trust the type annotation self._program can be either None or a QuantumProgram which is guaranteed to have a .code field of the any_pb2.Any type.

I was puzzled because or not self._program.code is effectively or False and thus redundant. I wondered if the intent was to have some non-const expression there so I suggested the value field. Otherwise I have no preference, dropping or not self._program.code would be fine with me too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's the types of QuantumProgram itself that concerns me, because the proto-plus library does some metaclass magic so it's not clear to me how its type annotations work. I'd prefer to keep this for defense in depth for now.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.57%. Comparing base (2ef9f37) to head (f5a2752).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7850   +/-   ##
=======================================
  Coverage   99.57%   99.57%           
=======================================
  Files        1104     1104           
  Lines       98988    98990    +2     
=======================================
+ Hits        98566    98569    +3     
+ Misses        422      421    -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.

@maffoo maffoo requested a review from pavoljuhas January 22, 2026 21:01
@github-actions github-actions bot added size: S 10< lines changed <50 and removed Size: XS <10 lines changed labels Jan 22, 2026
@maffoo
Copy link
Copy Markdown
Contributor Author

maffoo commented Jan 22, 2026

Updated tests to include case with a QuantumProgram with empty code field. PTAL, @pavoljuhas

@maffoo maffoo enabled auto-merge January 22, 2026 21:14
Copy link
Copy Markdown
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

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

Fixes b/477955102

Copy link
Copy Markdown
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

LGTM with an optional inline suggestion.

@maffoo maffoo added this pull request to the merge queue Jan 22, 2026
@pavoljuhas pavoljuhas removed this pull request from the merge queue due to a manual request Jan 22, 2026
@maffoo maffoo added this pull request to the merge queue Jan 22, 2026
Merged via the queue into main with commit f066e63 Jan 22, 2026
41 checks passed
@maffoo maffoo deleted the u/maffoo/engine-get-circuit branch January 22, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants