Skip to content

Add Prod, Sum, and SProd support to qp.is_commuting. #9501

@albi3ro

Description

@albi3ro

qp.is_commuting is a function to quickly determine whether or not two operators should be commuting.

While we support anything with a defined pauli_rep property, we explicitly error out if we encounter Sum , Prod, or SProd instances without a pauli_rep, see here.

>>> qp.is_commuting(qp.X(0) + qp.Y(1), 3* qp.X(0))
True
>>> op1 = qp.RX(0.5, 0) + qp.T(1)
>>> op2 = 2*qp.RX(0.5, 0) @ qp.T(1)
>>> qp.is_commuting(op1, op2)
QuantumFunctionError: Operation RX(0.5, wires=[0]) + T(1) currently not supported. Prod, Sprod, and Sum instances must have a valid Pauli representation.

Instead, we should add logic so that:

  1. If it commutes with the op.base of a qp.ops.SProd, it commutes with the SProd
  2. It commutes with all of the op.operands of a qp.ops.Prod or a qp.ops.Sum (qp.ops.CompositeOp), the it commutes with the operator itself.

Subtasks

A PR that solves this issue should:

  1. Add logic to is_commuting.py to support the above three types
  2. Adds tests to test_is_commuting.py
  3. Adds a changelog entry to changelog-dev.md under "Improvements", and adds your name to the list of contributors
  4. Follow our standards for pylint and black see here.

Any use of AI should conform to our AI Policy and be explicitly stated. Note that as this is "good first issue" intended to give newcomers experience contributing to open source software, I would like to discourage the use of AI to solve this issue.

Metadata

Metadata

Assignees

Labels

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions