question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merge `cirq.Pauli.X` and `cirq.X` into one object (do same for Y and Z)

See original GitHub issue

Currently, there is an unnecessary distinction between cirq.Pauli.X (an instance of cirq.Pauli) and cirq.X (an instance of cirq.RotXGate). Some code wants the pauli x, some wants the x rotation. We need to unify these two things into one thing.

I’m not exactly sure how this should be done.

One way would be to introduce a PauliXGate that is the unification of both concepts, and falls back into one or the other as methods are applied (e.g. cirq.X would be a PauliGate but cirq.X**0.5 would again be a RotXGate).

Another way is to destroy the Pauli class and replace it with a type such as Union[cirq.X, cirq.Y, cirq.Z], and all the class methods because just functions that can be applied to that type.

I’m labelling this “good part time project” because I think it’s reasonably “meaty” design-wise and amount-of-touched-code-wise. I expect it to require iteration to hit something that works well.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Strilanccommented, Oct 29, 2018

Some example use cases that I think should work:

Creating and exponentiating pauli products to create PauliStringPhasor operations that can be put into a circuit:

xy = cirq.X(q) * cirq.Y(p)
sqrt_xy = xy**0.5
c = cirq.Circuit.from_ops(sqrt_xy)

The future possibility of creating linear combinations of pauli products, which defines a QubitOperator (a term from openfermion):

hamiltonian = 0.5 * cirq.X(q) * cirq.Y(p) - cirq.Z(r)
0reactions
viathorcommented, Mar 13, 2019

Clarification on the status of cirq.Pauli: it still exists, but as abstract class. It has no public subclasses and only three instances: cirq.X, cirq.Y and cirq.Z, see #1249.

The class is used in type annotations and for its static methods that enable index-based access to the three instances, e.g. in the definition of SingleQubitCliffordGate class.

In [2]: isinstance(cirq.X, cirq.Pauli)
Out[2]: True

In [3]: isinstance(cirq.T, cirq.Pauli)
Out[3]: False

In [4]: cirq.X == cirq.Pauli.by_index(0)
Out[4]: True

In [5]: cirq.X == cirq.Pauli.by_index(1)
Out[5]: False

In [6]: cirq.Y == cirq.Pauli.by_index(1)
Out[6]: True
Read more comments on GitHub >

github_iconTop Results From Across the Web

cirq.PauliString - Google Quantum AI
cirq.PauliString represents a multi-qubit pauli operator, i.e. a tensor product of single qubit (non identity) pauli operations, each acting on ...
Read more >
Gates and operations | Cirq - Google Quantum AI
Z The Pauli gates X, Y, and Z which rotate the state around the associated axis by one half-turn. cirq.rx(rads) A rotation about...
Read more >
cirq.DensePauliString - Google Quantum AI
An immutable string of Paulis, like XIXY , with a coefficient. ... A DensePauliString represents a multi-qubit pauli operator, i.e. a tensor ...
Read more >
cirq.SingleQubitPauliStringGateOperation - Google Quantum AI
Returns the Pauli string conjugated by a clifford operation. ... For example, conjugating a +Y operation by an S operation results in a...
Read more >
Custom gates | Cirq - Google Quantum AI
The Pauli gates included in Cirq use the convention Z**0.5 ≡ S ≡ np.diag(1, i) , Z**-0.5 ≡ S**-1 , X**0.5 ≡ H·S·H...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found