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

Should analytical decompositions return an empty list when decomposing identity operation? #4831

Open
tanujkhattar opened this issue Jan 12, 2022 · 1 comment
Assignees
Labels
area/decomposition area/transformers kind/design-issue A conversation around design triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@tanujkhattar
Copy link
Collaborator

We have many analytical decompositions in https://github.com/quantumlib/Cirq/tree/master/cirq-core/cirq/transformers/analytical_decompositions which are used to decompose a given unitary matrix / operation into a specific target gateset (eg: cz/fsim/sqrt_iswap etc.). The behavior of these decompositions when trying to decompose an identity operation currently differs across implementations -- some return an empty list while some return only single qubit ops and others return a longer decomposition. Eg:

>>> import cirq
>>> import numpy as np
>>> eye = np.eye(4)
>>> q0, q1 = cirq.LineQubit.range(2)
>>> cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, eye)
[]
>>> cirq.two_qubit_matrix_to_operations(q0, q1, eye, allow_partial_czs=False, clean_operations=False)
[cirq.S(cirq.LineQubit(0)), (cirq.Z**1.5).on(cirq.LineQubit(0))]

There are also other inconsistencies in the API's of these analytical decompositions. For example:

  1. Calling a list of cleanup operations on the decomposed operation list:
  • two_qubit_matrix_to_operations has a default clean_operations=True flag in the constructor which calls a long list of cleanup operations on the list of final decomposed operations.
  • two_qubit_matrix_to_ion_operations does not have a configurable cleanup_operations=True flag and always calls the same list of cleanup operations on the final decomposed operations
  • two_qubit_matrix_to_sqrt_iswap_operations has no flag and does not call the cleanup operations on the final decomposed operations.
  1. API of the analytical decompositions:
  • two_qubit_matrix_to_* versions expect a q0, q1, mat
  • decompose_two_qubit_interaction_into_four_fsim_gates expects as Union['cirq.Operation', 'cirq.Gate', np.ndarray, Any] and a qubits: Sequence['cirq.Qid'] = None instead of q0, q1 etc.
  • decompose_cphase_into_two_fsim expects CZPowGate and FSimGates (not operations or matrices)
@tanujkhattar tanujkhattar added triage/discuss Needs decision / discussion, bring these up during Cirq Cynque kind/design-issue A conversation around design labels Jan 12, 2022
@viathor viathor added area/decomposition area/transformers triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Jan 12, 2022
@tanujkhattar
Copy link
Collaborator Author

tanujkhattar commented Jan 19, 2022

  • We should return cirq.I or [] .
  • Let's fix the API and make things more consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/decomposition area/transformers kind/design-issue A conversation around design triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
Status: No status
Development

No branches or pull requests

5 participants