Uh oh!
There was an error while loading. Please reload this page.
feat(python): load visual circuits directly in Context - #3291
Conversation
Stephen Smith (tzh476)
commented
Jun 4, 2026
@microsoft-github-policy-service agree |
Stephen Smith (tzh476)
commented
Jun 4, 2026
Hi Bill Ticehurst (@billti)Ian Davis (@idavis)Mine Starks (@minestarks), I have signed the CLA. Could you please approve the pending workflows and review when convenient? Thanks! |
f084b04 to
e70656bCompareUh oh!
There was an error while loading. Please reload this page.
Stephen Smith (tzh476)
commented
Jun 4, 2026
I addressed the GitHub Advanced Security / DevSkim review in |
Stephen Smith (tzh476)
commented
Jun 4, 2026
All refreshed checks are passing now, including Could you please review this when convenient? Thanks! |
Mine Starks (minestarks)
commented
Jun 5, 2026
Thank you Stephen Smith (@tzh476) ! I'm taking a look now - will post comments shortly. |
Mine Starks (minestarks)
left a comment
There was a problem hiding this comment.
Really nice contribution, thank you! Just a couple of requests, please.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Stephen Smith (tzh476)
commented
Jun 5, 2026
Thanks for the review. I pushed
Local validation: python3 -m py_compile source/qdk_package/qdk/_context.py source/qdk_package/tests/test_project.py
git diff --checkI attempted the targeted pytest locally, but this checkout cannot resolve the repository-local |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Mine Starks (minestarks)
commented
Jun 9, 2026
Stephen Smith (@tzh476) thank you for the edits! It's very close! I've been playing around with it on my machine, and found a couple of minor user-facing API/behavior concerns (see comments). Thank you! |
Stephen Smith (tzh476)
commented
Jun 9, 2026
Thanks for the follow-up. I pushed
I also updated the operation-mode expectation from Local validation: python3 -m py_compile source/qdk_package/qdk/_context.py source/qdk_package/qdk/__init__.py source/qdk_package/tests/test_project.py
git diff --checkThe local checkout here still does not have the built |
Thanks for the clarification from Stefan J. Wernli (@swernli). I pushed
Local validation passed: python3 -m py_compile source/qdk_package/qdk/_context.py source/qdk_package/qdk/__init__.py source/qdk_package/tests/test_project.py
git diff --checkThe native-backed targeted pytest needs the repository build/test environment, so I am relying on the refreshed GitHub CI run for that coverage. Could you please approve the refreshed workflows and review when convenient? Thanks! |
Mine Starks (minestarks)
commented
Jun 9, 2026
Stephen Smith (@tzh476) hmm, the CI checks failed. You can run the same CI checks by just running The problem seems to be that marking the operation Let's try to address it deeper within the native code / Rust layer. We can refactor things a bit. Can we avoid generating 2 operations altogether, and have just ONE named It seems that the solution would be to refactor See unit tests at |
Stephen Smith (tzh476)
commented
Jun 10, 2026
I saw the refreshed Local validation passed again: python3 -m py_compile source/qdk_package/qdk/_context.py source/qdk_package/qdk/__init__.py source/qdk_package/tests/test_project.py
git diff --checkThis should address the two failing assertions from the previous CI run while preserving the public File/Operation behavior discussed above. |
Stefan J. Wernli (swernli)
commented
Jun 10, 2026
Superseded by the native Rust-layer follow-up in |
Stephen Smith (tzh476)
commented
Jun 10, 2026
Thanks for the detailed guidance. I replaced the Python-side wrapper/helper approach with a native Rust-layer standalone path in What changed:
Local validation passed: ./build.py --qdk --test --no-check-prereqs --no-check
RUSTUP_HOME=/Users/bytedance/Library/Caches/puccinialin/rustup CARGO_HOME=/Users/bytedance/Library/Caches/puccinialin/cargo cargo fmt --check --all
cargo test -p qsc_circuit circuit_to_qsharp
source/qdk_package/.venv/bin/python -m pytest source/qdk_package/tests/test_project.py -k import_circuit -q
python3 -m py_compile source/qdk_package/qdk/_context.py source/qdk_package/qdk/__init__.py source/qdk_package/qdk/_native.pyi source/qdk_package/tests/test_project.py
git diff --checkThe linked failed Could you please approve the refreshed workflows and review when convenient? Thanks! |
Stephen Smith (tzh476)
commented
Jun 11, 2026
Quick status update after the native Rust-layer refactor in |
Change-Id: I3b8a9eadb78dbe1f61b1ebb058a78bc1b0985a29
Change-Id: Id6234644a0f42eab2b6e6472df0464521947c71a
Change-Id: I962310d4ae6aaf624aee2632d0d0f5bb7b589328
Change-Id: I07504f28c2001e92d220f96d3bca5dff492fdbf7
Change-Id: I4c9feeb6d09968b436fdb85ea71c47b8f414310e
Change-Id: I3f2af6e35350c9716b1c8c31dbf018e7d338b104
Change-Id: I5b3e04d51a22a1760a10b95e7b69b2b547a7113e
Change-Id: I976285e0e7a28b0249632f6ba5bafc545ee65670
87c37b7 to
66e996fCompareFollow-up: I rebased the branch onto the latest Post-rebase local validation now passes with the repository package build/test flow: ./build.py --qdk --test --no-check-prereqs --no-checkResult: the QDK Python wheel built successfully, and the Python package test suite completed with The only currently visible check is still the CLA check, so the refreshed workflows appear to need approval/re-run for the rebased head as well. |
Mine Starks (minestarks)
left a comment
There was a problem hiding this comment.
Tested. One last round of minor cleanup comments - I think the user-facing API and behavior are all there. Thank you!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Change-Id: Ib5a34348e3c49d941dcd457b47117016dfa17fef
Stephen Smith (tzh476)
commented
Jun 11, 2026
Pushed Changes:
Local validation passed: python3 -m py_compile source/qdk_package/qdk/_context.py source/qdk_package/tests/test_project.py
git diff --check
source/qdk_package/.venv/bin/python -m pytest source/qdk_package/tests/test_project.py -k import_circuit -q
./build.py --qdk --test --no-check-prereqs --no-checkFull build/test result: I also replied to and resolved the three review threads. |
Uh oh!
There was an error while loading. Please reload this page.
Fixes#3232. - add `Context.import_circuit(path, *, index=0, name=None, program_type=ProgramType.File)` for standalone `.qsc` visual-circuit files - support selecting a circuit from multi-circuit `.qsc` files with `index=0` by default - default `ProgramType.File` imports a single zero-argument Q# operation named from the file stem, or from the optional `name=` override, suitable for `ctx.run(...)` and `ctx.circuit(...)` - support `ProgramType.Operation` for registering the qubit-taking circuit operation directly so it can be composed from Q# entry expressions - generate the standalone File-mode Q# operation in the native Rust layer via `qsc_circuit`, avoiding Python-side helper/wrapper cleanup and avoiding extra public helper callables in `qdk.code` - re-export `ProgramType` from `qdk` for the new import mode selection - cover direct visual-circuit import, multi-circuit selection, Operation mode, and explicit name override in Python tests; add native `qsc_circuit` tests for standalone Q# generation I used Codex to help inspect the existing QDK visual-circuit conversion path, draft the Python/Rust integration changes, respond to review feedback, and prepare tests. I manually reviewed the patch and verified it locally with the checks below. Latest post-rebase validation on `66e996fe5`: ```bash ./build.py --qdk --test --no-check-prereqs --no-check ``` Result: the QDK Python wheel built successfully, and the Python package test suite completed with `1401 passed, 84 skipped, 1 xfailed`. Additional targeted checks run during the native Rust-layer refactor: ```bash RUSTUP_HOME=/Users/bytedance/Library/Caches/puccinialin/rustup CARGO_HOME=/Users/bytedance/Library/Caches/puccinialin/cargo cargo fmt --check --all cargo test -p qsc_circuit circuit_to_qsharp source/qdk_package/.venv/bin/python -m pytest source/qdk_package/tests/test_project.py -k import_circuit -q python3 -m py_compile source/qdk_package/qdk/_context.py source/qdk_package/qdk/__init__.py source/qdk_package/qdk/_native.pyi source/qdk_package/tests/test_project.py git diff --check ```


Fixes#3232.
Summary
Context.import_circuit(path, *, index=0, name=None, program_type=ProgramType.File)for standalone.qscvisual-circuit files.qscfiles withindex=0by defaultProgramType.Fileimports a single zero-argument Q# operation named from the file stem, or from the optionalname=override, suitable forctx.run(...)andctx.circuit(...)ProgramType.Operationfor registering the qubit-taking circuit operation directly so it can be composed from Q# entry expressionsqsc_circuit, avoiding Python-side helper/wrapper cleanup and avoiding extra public helper callables inqdk.codeProgramTypefromqdkfor the new import mode selectionqsc_circuittests for standalone Q# generationAI Assistance Disclosure
I used Codex to help inspect the existing QDK visual-circuit conversion path, draft the Python/Rust integration changes, respond to review feedback, and prepare tests. I manually reviewed the patch and verified it locally with the checks below.
Testing
Latest post-rebase validation on
66e996fe5:Result: the QDK Python wheel built successfully, and the Python package test suite completed with
1401 passed, 84 skipped, 1 xfailed.Additional targeted checks run during the native Rust-layer refactor:
RUSTUP_HOME=/Users/bytedance/Library/Caches/puccinialin/rustup CARGO_HOME=/Users/bytedance/Library/Caches/puccinialin/cargo cargo fmt --check --all cargo test -p qsc_circuit circuit_to_qsharp source/qdk_package/.venv/bin/python -m pytest source/qdk_package/tests/test_project.py -k import_circuit -q python3 -m py_compile source/qdk_package/qdk/_context.py source/qdk_package/qdk/__init__.py source/qdk_package/qdk/_native.pyi source/qdk_package/tests/test_project.py git diff --check