-
Notifications
You must be signed in to change notification settings - Fork 984
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
Update Neutral Atoms to Transformers #5311
Update Neutral Atoms to Transformers #5311
Conversation
Create function convert_to_neutral_atom_gateset() to replace PointOptimizer ConvertToNeutralAtomGateset. Create NeutralAtomGateset that works as a compilation target gateset.
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.
Looking good overall. Main concern is to avoid introducing the additional convert_to_neutral_atom_gates
transformer and instead use the standard API of cirq.optimize_for_target_gateset(circuit, gateset=cirq.NeutralAtomGateset())
|
||
if TYPE_CHECKING: | ||
import cirq | ||
|
||
|
||
@transformers.transformer | ||
def convert_to_neutral_atom_gates( |
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 just update the deprecation message in ConvertToNeutralAtomGates
to point users to the cirq.optimize_for_target_gateset(circuit, gateset=cirq.NeutralAtomGateset)
API instead of creating this additional transformer which is essentially just a wrapper. WDYT ?
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.
SGTM, done.
|
||
|
||
class NeutralAtomGateset(transformers.CompilationTargetGateset): | ||
def __init__(self, max_parallel_z=None, max_parallel_xy=None): |
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.
nit: Add type annotations to arguments.
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.
Done.
import cirq | ||
|
||
|
||
class NeutralAtomGateset(transformers.CompilationTargetGateset): |
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.
nit: Add docstring
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.
Done.
Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
cirq-core/cirq/__init__.py
Outdated
@@ -668,6 +668,7 @@ | |||
|
|||
from cirq.ion import ConvertToIonGates, IonDevice, ms, two_qubit_matrix_to_ion_operations | |||
from cirq.neutral_atoms import ( | |||
convert_to_neutral_atom_gates, |
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.
Remove import
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.
Done.
|
||
if TYPE_CHECKING: | ||
import cirq | ||
|
||
|
||
@deprecated_class( | ||
deadline='v0.16', | ||
fix='Use cirq.optimize_for_target_gateset(' + 'circuit, gateset=NeutralAtomGateset()).', |
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.
Why the break into 2 different strings?
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.
Combined.
return 2 | ||
|
||
def decompose_to_target_gateset(self, op: 'cirq.Operation', moment_idx: int) -> DecomposeResult: | ||
"""Method to rewrite the given operation using gates from this gateset. |
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.
Add to the docstring that 2q gates are decomposed into CZs because "CZ gates are the highest fidelity 2-qubit gates for neutral atoms." (quoted from docstring of ConvertToNeutralAtomGates optimizer)
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.
Done.
* Update Neutral Atoms to Transformers Create NeutralAtomGateset that works as a compilation target gateset. Point ConvertToNeutralAtomGateset towards optimize_for_target_gateset instead.
Create function convert_to_neutral_atom_gateset() to
replace PointOptimizer ConvertToNeutralAtomGateset.
Create NeutralAtomGateset that works as a compilation target
gateset.