Define Custom Operations via the C API - #16549
Open
raynelfss wants to merge 19 commits into
Open
Conversation
raynelfss
force-pushed
the
c-custom-gates
branch
from
July 10, 2026 14:57
e04240c to
58079e3
Compare
raynelfss
force-pushed
the
c-custom-gates
branch
from
July 22, 2026 15:15
5109846 to
1e949ac
Compare
- The new check makes sure that none of the pointers belonging to the `CustomOp` instance are null or unaligned.
Collaborator
|
One or more of the following people are relevant to this code:
|
3 tasks
3 tasks
…ations - Make `CustomOp` the private representation of `C Custom`. - Make `BoxedCustomOperation` public and use it as the way to expose `CustomOperation` to C as it already is a `Boxed` pointer. - Update each usage to leverage `Boxed` pointer. - Rename `qk_custom_op_new_vtable` to `qk_custom_op_vtable_new`.
Coverage Report for CI Build 33197765241Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage increased (+0.09%) to 87.681%Details
Uncovered Changes
Coverage Regressions2378 previously-covered lines in 36 files lost coverage.
Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix #16621
The following commits introduce Custom Operations to the C API by doing the following:
QkCircuitandQkDAGvia the new methods.Detailed breakdown
Since #15573 closed, we now have the ability of defining custom operations without needing to interact with Python. Having the ability to use dynamic dispatching to define operations while also allowing them to have the minimal amount of functionality needed for them to work inside a circuit.
The following commits add the ability to do the same using the C API in a more explicit way.
Custom Operations in C
A custom operation defined in C is currently represented by the struct
QkCustomOperation(representingBoxedCustomOperation), which essentially wraps a struct with two fields.orig: A pointer to the operation struct instance to be added to the circuit.v_table: A pointer to theQkCustomOpVtableto be used for accessing the methods that establish minimal functionality for an operation.QkCustomOpVtableThis
v_tablecontains the slots referring the required/optional methods for anOperationto work. This includes the following methods:nameconst void *char *num_qubitsconst void *uint32_tnum_clbitsconst void *uint32_tnum_paramsconst void *uint32_tdirectiveconst void *boolis_unitaryconst void *boolnum_ctrl_qubitsconst void *uint32_tlabelconst void *char *definitionconst void *,QkParam *QkCircuit *eqconst void *,const void *boolRefer the included documentation to further understand how it works.
Circuit methods
Two functions to add custom operations to a circuit have been included in this PR:
qk_circuit_add_custom_operation: To add to anyQkCircuitinstance.qk_dag_apply_custom_operation: To add to anyQkDAGinstance.AI/LLM disclosure