Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target gate set for cirq benchmarking #224

Merged
merged 2 commits into from
Feb 14, 2025
Merged

Add target gate set for cirq benchmarking #224

merged 2 commits into from
Feb 14, 2025

Conversation

bachase
Copy link
Collaborator

@bachase bachase commented Feb 12, 2025

cirq's optimize_for_target_gateset function requires providing a class that compiles to a desired target gateset. None of the cirq provided target gatesets use the set of gates we consider for benchmarking, so this change adds an appropriate one with our desired basis.

Fixes #201 .

@bachase
Copy link
Collaborator Author

bachase commented Feb 12, 2025

@Misty-W I went with a smaller change that just directly addresses the issue. I created #225 as a follow on to setup added checks in the benchmarking code to detect if this type of issue were to reoccur in the future.

@bachase
Copy link
Collaborator Author

bachase commented Feb 12, 2025

I manually triggered a benchmark run again so reviewers can see that compilation still works. I'll plan to delete that commit before merging

I have a comment in #146 that could simplify this workflow in the future.

@bachase bachase requested a review from natestemen February 13, 2025 11:53
Copy link
Member

@natestemen natestemen left a comment

Choose a reason for hiding this comment

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

Looks good, and nice finds with the single and two qubit gate decomposition functions. A few questions, but no blockers.

Should we add a permalink to the code you based this on as a comment so it's easier to come back to later?

"""Target gateset for compiling circuits for benchmarking.

This is modeled off cirq's CZCompilationTargetGateset, but instead:
* Decomposes single-qubit gates into Rz, Ry, and Rz gates versus XZPowGate.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Decomposes single-qubit gates into Rz, Ry, and Rz gates versus XZPowGate.
* Decomposes single-qubit gates into Rz, Ry, Rz, and H gates versus XZPowGate.

Copy link
Collaborator Author

@bachase bachase Feb 13, 2025

Choose a reason for hiding this comment

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

Good catch. I will tweak slightly toDecomposes non target gateset single-qubit gates into Rz, Ry gates versus XZPowGate. so that it's clearer we are decomposing the arbitrary single-qubit gates to just the RzRyRz, but leave X and H gates alone since the are already in the target gateset.

Copy link
Member

Choose a reason for hiding this comment

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

Ahhh okay yeah I misunderstood that. Thanks for clarifying.

)

def _decompose_single_qubit_operation(
self, op: cirq.Operation, _
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self, op: cirq.Operation, _
self, op: cirq.Operation

Not suggesting this argument is removed, but just trying to highlight it. What is this argument for if it's not used? I guess required for some ABC?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Somewhat -- it was to override the same method in the base class (https://github.com/quantumlib/Cirq/blob/dd3df78c045a03b2de70b2d54d8582abbfc1f6c2/cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py#L257). Its not strictly abstract since the base class provides a definition.

But I can actually name this to moment. I'm not sure why I switched to unnamed as I don't think the linting rules required it. I'll put it back as its clearer!

Copy link
Member

Choose a reason for hiding this comment

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

Do test directories need init files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I don't think they do as pytest should still discover them. Its just habit for me, as there's the off chance there's some importing or other tooling that might want to treat it as a package.

Comment on lines +30 to +33
expected_gates = cirq.Gateset(cirq.CNOT, cirq.Rx, cirq.Ry, cirq.Rz, cirq.H)
assert expected_gates.validate(c_new), (
"Cirq compilation had unsupported gatges"
)
Copy link
Member

Choose a reason for hiding this comment

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

I'm learning about so many cirq functions through this PR! Good stuff.

cirq's optimize_for_target_gateset function requires providing a
class that compiles to a desired target gateset. None of the cirq
provided target gatesets use the set of gates we consider for benchmarking, so
this change adds an appropriate one,
@bachase
Copy link
Collaborator Author

bachase commented Feb 13, 2025

Thanks for the feedback @natestemen! I went ahead and dropped the prior benchmark run from the git lineage.

Copy link
Member

@natestemen natestemen left a comment

Choose a reason for hiding this comment

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

:shipit:

@bachase bachase merged commit d7e62be into main Feb 14, 2025
1 check passed
@bachase bachase deleted the 201-cirq-gateset branch February 14, 2025 00:29
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.

Cirq compiles to unexpected gateset
2 participants