Skip to content

Conversation

@lmondada
Copy link
Collaborator

@lmondada lmondada commented Nov 7, 2025

Description

This PR creates a system to register Decomposition patterns and associate metadata to them. This will be useful in an upcoming PR, where the metadata about what gate type is matched and what gate type is introduced by a rewrite will be used to select the subsets of pattern rewrites useful to target a specified target basis (see #3581).

With or without macro?

I tried to avoid using a macro here, but the same ~15 lines are repeated 31 times (once for each decomposition pattern).
A macro can remove this redundancy. What do you prefer?

To make reviewing easier, the first commit introduces all the changes without using a macro. The second commit then introduces the macro and removes redundancies. Getting rid of the macro is thus as simple as removing the second commit, if that's desired.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Nov 7, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@lmondada lmondada force-pushed the lm/pattern-metadata branch from 623f8ae to f7bd459 Compare November 7, 2025 15:14
}

// Test 3: Verify pattern decompositions produce only target gates
TEST_F(DecompositionPatternsTest, DecompositionProducesOnlyTargetGates) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test is quite verbose/ugly (see also createTestModule). Is there a better way to write it?

@lmondada lmondada marked this pull request as ready for review November 7, 2025 15:32
@lmondada
Copy link
Collaborator Author

lmondada commented Nov 7, 2025

/ok to test f7bd459

Command Bot: Processing...

github-actions bot pushed a commit that referenced this pull request Nov 7, 2025
@github-actions
Copy link

github-actions bot commented Nov 7, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

@lmondada lmondada marked this pull request as draft November 17, 2025 07:59
@lmondada lmondada force-pushed the lm/pattern-metadata branch 2 times, most recently from 66dcd3e to 0727390 Compare November 18, 2025 18:49
@lmondada lmondada force-pushed the lm/pattern-metadata branch from 0727390 to 12252ad Compare November 18, 2025 18:52
@lmondada lmondada marked this pull request as ready for review November 18, 2025 18:52
@lmondada lmondada requested a review from sacpis November 18, 2025 19:04

// Test 1: Verify the total number of registered decomposition patterns
TEST_F(DecompositionPatternsTest, TotalPatternCount) {
auto patternNames = cudaq::DecompositionPatternType::RegistryType::entries();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering if we can fetch the entries just once and use it in all tests, as we are not changing anything in it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes we can, but in this case I don't think it's useful: entries() returns an iterator, which from the implementation seems very cheap (pretty much free) to construct.

auto [gatePrefix, gateNum] = splitGateAndControls(gate);

for (auto targetGate : targetGates) {
auto [tPrefix, tNum] = splitGateAndControls(targetGate);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a thought. What if we already store targetGates in a map with prefix as key and num as value? That way we don't have to iterate the list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 have implemented your suggestion.

Copy link
Collaborator

@sacpis sacpis left a comment

Choose a reason for hiding this comment

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

Overall this PR looks good to me. Would like @schweitzpgi to have a look at it as well.

@sacpis
Copy link
Collaborator

sacpis commented Nov 18, 2025

Seems like few tests are failing in CI.
https://github.com/NVIDIA/cuda-quantum/actions/runs/19477582015/job/55742702956?pr=3587#step:9:2070

@sacpis sacpis requested a review from schweitzpgi November 18, 2025 21:51
@sacpis
Copy link
Collaborator

sacpis commented Nov 19, 2025

Adding @khalatepradnya to take a look at it as well.

@lmondada
Copy link
Collaborator Author

Seems like few tests are failing in CI. https://github.com/NVIDIA/cuda-quantum/actions/runs/19477582015/job/55742702956?pr=3587#step:9:2070

Indeed! My guess is that this is due to a change in ordering of the patterns in the RewritePatternSet. I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants