Skip to content

Improve __pow__ for SingleQubitCliffordGate and CliffordGate class #6327

@NoureldinYosri

Description

@NoureldinYosri

Is your feature request related to a use case or problem? Please describe.
The __pow__ operator for CliffordGate is implemented only for integer powers and has complexity $\mathcal{O}(n)$ where $n$ is the exponent.

def __pow__(self, exponent) -> 'CliffordGate':
if exponent == -1:
return CliffordGate.from_clifford_tableau(self.clifford_tableau.inverse())
if exponent > 0 and int(exponent) == exponent:
base_tableau = self.clifford_tableau.copy()
for _ in range(int(exponent) - 1):
base_tableau = base_tableau.then(self.clifford_tableau)
return CliffordGate.from_clifford_tableau(base_tableau)
if exponent < 0 and int(exponent) == exponent:
base_tableau = self.clifford_tableau.copy()
for _ in range(int(-exponent) - 1):
base_tableau = base_tableau.then(self.clifford_tableau)
return CliffordGate.from_clifford_tableau(base_tableau.inverse())

For SingleQubitCliffordGate it's implemented for only integer powers where it falls to CliffordGate.__pow__ and for $\pm \sqrt{}$.

def __pow__(self, exponent) -> 'SingleQubitCliffordGate':
# First to check if we can get the sqrt and negative sqrt Clifford.
if self._get_sqrt_map().get(exponent, None):
pow_gate = self._get_sqrt_map()[exponent].get(self, None)
if pow_gate:
return pow_gate
# If not, we try the Clifford Tableau based method.
ret_gate = super().__pow__(exponent)
if ret_gate is NotImplemented:
return NotImplemented
return SingleQubitCliffordGate.from_clifford_tableau(ret_gate.clifford_tableau)

Describe the solution you'd like
For CliffordGate.__pow__ exponentiation should be done using binary exponentiation to reduce the complexity ot $\mathcal{O}(\log{n})$. Support for non integer exponents is hard in the general case.

For SingleQubitCliffordGate.__pow__. The single qubit clifford gates are a group of size 24. see.

def all_single_qubit_cliffords(cls) -> Sequence['cirq.SingleQubitCliffordGate']:

support for integer powers can be done in $\mathcal{O}(1)$ if we either fall to the optimized CliffordGate.__pow__ but with exponent%24 instead of expnent or cache the results in table and access group_powers[self][exponent%24]. For rational exponents, When the clifford operation has a sqrt. The operation becomes well defined for exponents of the form $\frac{k}{2}$ where $k \in \mathbb{Z}$. For example $X^\frac{5}{2}$ is the same as $SqrtX^5$ and $X^\frac{-5}{2}$ which is the same as $(SqrtX^\dagger)^5$.

What is the urgency from your perspective for this issue? Is it blocking important work?

P3 - I'm not really blocked by it, it is an idea I'd like to discuss / suggestion based on principle

Metadata

Metadata

Labels

good first issueThis issue can be resolved by someone who is not familiar with the codebase. A good starting issue.good for learningFor beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues"kind/feature-requestDescribes new functionalitytriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions