Skip to content

Conversation

@jakelishman
Copy link
Member

This adds qk_dag_get_instruction as a mirror to
qk_circuit_get_instruction (unifying the code in anticipation of making it lower-allocation in the future), and the standard-instruction application functions qk_dag_apply_measure, qk_dag_apply_barrier and qk_dag_apply_reset.

We're still missing qk_dag_apply_unitary, but that's for a different commit.

Summary

Details and comments

Close #15193
Close #15311

This adds `qk_dag_get_instruction` as a mirror to
`qk_circuit_get_instruction` (unifying the code in anticipation of
making it lower-allocation in the future), and the standard-instruction
application functions `qk_dag_apply_measure`, `qk_dag_apply_barrier` and
`qk_dag_apply_reset`.

We're still missing `qk_dag_apply_unitary`, but that's for a different
commit.
@jakelishman jakelishman requested a review from a team as a code owner November 7, 2025 18:31
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@jakelishman jakelishman added this to the 2.3.0 milestone Nov 7, 2025
@github-project-automation github-project-automation bot moved this to Ready in Qiskit 2.3 Nov 7, 2025
@jakelishman jakelishman added Changelog: New Feature Include in the "Added" section of the changelog C API Related to the C API labels Nov 7, 2025
@coveralls
Copy link

coveralls commented Nov 7, 2025

Pull Request Test Coverage Report for Build 19687548632

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 111 of 134 (82.84%) changed or added relevant lines in 2 files are covered.
  • 245 unchanged lines in 7 files lost coverage.
  • Overall coverage increased (+0.01%) to 88.243%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/cext/src/circuit.rs 31 32 96.88%
crates/cext/src/dag.rs 80 102 78.43%
Files with Coverage Reduction New Missed Lines %
crates/circuit/src/parameter/parameter_expression.rs 1 82.3%
crates/circuit/src/parameter/symbol_expr.rs 1 73.35%
crates/qasm2/src/expr.rs 1 93.82%
crates/transpiler/src/passes/unitary_synthesis.rs 1 92.57%
crates/cext/src/dag.rs 3 84.04%
crates/qasm2/src/lex.rs 4 92.29%
crates/circuit/src/dag_circuit.rs 234 84.53%
Totals Coverage Status
Change from base Build 19678997564: 0.01%
Covered Lines: 94483
Relevant Lines: 107071

💛 - Coveralls

Copy link

@Shobhit21287 Shobhit21287 left a comment

Choose a reason for hiding this comment

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

Hi Jake, this looks good! Until we can represent operations generally, its good to have these as different function.

@raynelfss raynelfss self-assigned this Nov 11, 2025
@jakelishman
Copy link
Member Author

Shobit: thanks for doing the review! When you're submitted a PR review, there's a choice of three options for the review: "comment", "approve" and "request changes". If your review is saying "I think this is good to merge", you want to check the "approve" button instead of leaving it on "comment".

(We don't usually use "request changes" - we just leave those as "comment" - because "request changes" puts an actual block on merge, and requires the same reviewer to come back and dismiss their stale review.)

Copy link
Contributor

@raynelfss raynelfss left a comment

Choose a reason for hiding this comment

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

This functionally looks good to me, I saw a couple of things here and there when it came to documentation. And, assuming because of #15221 we won't be adding a release note here. So feel free to ping me once the documentation issues are solved.

/// This must be cleared by a call to `qk_circuit_instruction_clear` to avoid leaking its
/// allocations.
///
/// Panics if the operation name contains a nul, or if the instruction has non-float parameters.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this meant to be nul or is it a typo? It shows up later in the code so I'm assuming it's some meaning I don't know of, but in case it isn't.

Suggested change
/// Panics if the operation name contains a nul, or if the instruction has non-float parameters.
/// Panics if the operation name contains a null, or if the instruction has non-float parameters.

Copy link
Member Author

Choose a reason for hiding this comment

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

The ASCII \0 byte is referred to by both "nul" and "null" - the former comes from its three-letter short representation. We use nul elsewhere in the docs for it at the moment, so we might want to tidy up uniformly later.

@eliarbel eliarbel moved this from Ready to In review in Qiskit 2.3 Nov 13, 2025
Co-authored-by: Raynel Sanchez <[email protected]>
Copy link
Contributor

@raynelfss raynelfss left a comment

Choose a reason for hiding this comment

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

This looks good to me. There's a couple things in the documentation that could be improved upon though.

@raynelfss raynelfss added this pull request to the merge queue Nov 26, 2025
Merged via the queue into Qiskit:main with commit 32ac8c3 Nov 26, 2025
23 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in Qiskit 2.3 Nov 26, 2025
@jakelishman jakelishman deleted the dag-get-instruction branch November 26, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C API Related to the C API Changelog: New Feature Include in the "Added" section of the changelog

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add qk_dag_get_instruction to C API Add DAG standard-instruction apply operation front / back to C API.

5 participants