-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 cirq.CZTargetGateset
to replace cirq.ConvertToCZAndSingleGates
and cirq.MergeInteractions
#5007
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few high level questions before detailed review. Main one is why do we need another level of interface granularity between TwoQubitCompilationTargetGateset
and CompilationTargetGateset
? It seems the gains in having this are pretty small unless I'm missing something.
1: ───────────@───@────────────────────────────────────@─── | ||
│ | ||
2: ───────────────@──────────────────────────────────────── |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: how did this happen ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens because the newly introduced transformer is moment-preserving. Specifically, the original circuit is:
0: ───X───Y───Z───X^0.5───Y^0.5───S───X^-0.5───Y^-0.5───S^-1───H───@───X^0.25───Y^0.25───T───@───
│ │
1: ────────────────────────────────────────────────────────────────@───@─────────────────────@───
│
2: ────────────────────────────────────────────────────────────────────@─────────────────────────
In the first step, the following connected component gets merged and compiled:
[ 0: ───X───Y───Z───X^0.5───Y^0.5───S───X^-0.5───Y^-0.5───S^-1───H───@───X^0.25───Y^0.25───T─── ]
0: ───[ │ ]────────────────────────────────────────
[ 1: ────────────────────────────────────────────────────────────────@───────────────────────── ]['_default_merged_k_qubit_unitaries']
│
1: ───#2───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
as a result we have the following (moment-preserving) circuit:
0: ───PhXZ(a=0.5,x=0.5,z=0)───@───PhXZ(a=0.304,x=0.333,z=0.142)───────@───
│ │
1: ───────────────────────────@───────────────────────────────────@───@───
│
2: ───────────────────────────────────────────────────────────────@───────
whereas in the original workflow, the CZ(1, 2)
would have overlapped with PhXZ
in moment-2. The final compilation step beyond this point (ConvertToPauliStringPhasors
) has not yet been migrated to the new primitives, as a result in the final output, CZ(1, 2)
is just shifted to the right by 1 unit but still overlaps with a single qubit gate introduced due to ConvertToPauliStringPhasors
.
This is technically a breaking change but I'm not too worried because it's in contrib/
.
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Show resolved
Hide resolved
This is to avoid replicating the logic currently implemented in
Note that 3b will not necessarily be the case always and therefore it's important to not replace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few nits, but after resolved we should be good to merge.
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Outdated
Show resolved
Hide resolved
|
||
1. Expand composite gates acting on > 2 qubits using | ||
2. Merge connected components of 1 and 2 qubit unitaries into tagged circuit operations. | ||
3. Use `_decompose_single_qubit_operation` and `_decompose_two_qubit_operation` to figure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we expect users of this to interface to atleast have to override _decompose_two_qubit_operation
we should probably make it public ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep it private because _decompose_two_qubit_operation
is not supposed to be accessed from outside the class. The docstrings do specify that self._decompose_two_qubit_operation
is an abstract method and should be overwritten by the users. I don't see why we need to make it public.
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Show resolved
Hide resolved
@MichaelBroughton Addressed all comments and also added serialization support for the |
…n op tree is a generator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
None or NotImplemented if decomposition of `op` is unknown. | ||
""" | ||
return ( | ||
ops.PhasedXZGate.from_matrix(protocols.unitary(op)).on(op.qubits[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is PhasedXZ general enough to multiple architectures to be placed in cirq-core?
…` and `cirq.MergeInteractions` (quantumlib#5007) * Add CZTargetGateset to replace ConvertToCZAndSingleGates and MergeInteractions * Address feedback and add serialization support for CZTargetGateset. * Flatten new optree before computing new_2q_gate_count so it works when op tree is a generator.
…` and `cirq.MergeInteractions` (quantumlib#5007) * Add CZTargetGateset to replace ConvertToCZAndSingleGates and MergeInteractions * Address feedback and add serialization support for CZTargetGateset. * Flatten new optree before computing new_2q_gate_count so it works when op tree is a generator.
…` and `cirq.MergeInteractions` (quantumlib#5007) * Add CZTargetGateset to replace ConvertToCZAndSingleGates and MergeInteractions * Address feedback and add serialization support for CZTargetGateset. * Flatten new optree before computing new_2q_gate_count so it works when op tree is a generator.
Adds the following new primitives:
cirq.TwoQubitCompilationTargetGateset
: Abstract base class to facilitate defining two qubit compilation target gatesets.cirq.CZTargetGateset
: Compilation target gatesets for CZ + Single Qubit Rotations + Measurement gate. Used to deprecatecirq.MergeInteractions
optimizer andcirq.ConvertToCZAndSingleGates
optimizer.Part of Organization (and deprecation) of cirq-core/optimizers in cirq-core/transformers #4722
Follows the new Transformer API Compiling: Circuit Transformers API #4483
Supports no compile tags NoCompile Tag for optimizers NoCompile Tag for optimizers #4253
A step towards fixing cirq.MergeInteractions should also allow FSim and other future decompositions #4214
cc @MichaelBroughton @dstrain115