feat(python): load visual circuits directly in Context#3291
Conversation
|
@microsoft-github-policy-service agree |
|
Hi @billti @idavis @minestarks, I have signed the CLA. Could you please approve the pending workflows and review when convenient? Thanks! |
Change-Id: I3b8a9eadb78dbe1f61b1ebb058a78bc1b0985a29
f084b04 to
e70656b
Compare
Change-Id: Id6234644a0f42eab2b6e6472df0464521947c71a
|
I addressed the GitHub Advanced Security / DevSkim review in |
|
All refreshed checks are passing now, including Could you please review this when convenient? Thanks! |
|
Thank you @tzh476 ! I'm taking a look now - will post comments shortly. |
minestarks
left a comment
There was a problem hiding this comment.
Really nice contribution, thank you! Just a couple of requests, please.
Change-Id: I962310d4ae6aaf624aee2632d0d0f5bb7b589328
|
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 |
| wrapper_name = f"{circuit_operation_name}_Entry" | ||
| wrapper_source = _visual_circuit_wrapper_source( | ||
| circuit_operation_name, wrapper_name, qubit_count, return_type | ||
| ) |
There was a problem hiding this comment.
Question to @swernli - so this results in two callables - Foo and Foo_Entry . When we discussed in person, I hadn't considered that we'd end up with two callables. I actually like it this way - having the inner operation that takes Qubits continue to be called Foo. Thoughts?
There was a problem hiding this comment.
Hmm... I could see how this would be convenient for advanced users but worry that creating two similarly named callables might make this more confusing for average users. I think matching the behavior of how import_openqasm behaves with regard to ProgramType is easier to explain, where File creates one standalone callable that doesn't take qubit params and Operation creates the callable that takes qubits and can be used along with other code.
|
@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! |
Change-Id: I07504f28c2001e92d220f96d3bca5dff492fdbf7
|
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 |
Change-Id: I4c9feeb6d09968b436fdb85ea71c47b8f414310e
|
Thanks for the clarification from @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! |
|
@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 |
Fixes #3232.
Summary
Context.load_circuit(path, *, index=0)for standalone.qscvisual circuit files.qscfiles withindex=0by defaultContextand return a zero-argument callable suitable forctx.run(...)andctx.circuit(...)AI Assistance Disclosure
I used Codex to help inspect the existing QDK visual-circuit conversion path, draft the Python/Rust integration changes, and prepare tests. I manually reviewed the patch and verified it locally with the checks below.
Testing
test_load_circuitpassed, and all 12 tests intest_project.pypassed.