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

274 building xppauli classes (part of 257) #281

Merged
30 commits merged into from
Nov 14, 2022

Conversation

dhruvbhq
Copy link
Collaborator

Summary

Partial fix for #274 (part of #257 ). This PR contains an initial implementation of XPPauli and XPPauliList classes.

Details and comments

This is an initial implementation of XP operator algebra (from Mark Webster's package ) for XPPauli and XPPauliList. This is a work in progress.

  • Added classes XPPauli and XPPauliList and associated test files.
  • Functions implemented:
    • random_xppauli in operators/random.py
  • Functionality implemented in BaseXPPauli (XP* are function names from Mark's code, name in brackets is the new name):
    • XPSetN (rescale_precision)
    • XPDistance (weight)
    • XPisDiag (is_diagonal)
    • XPDegree (degree)
    • XPPower (power)
    • XPMul (compose)
    • XPRound (unique_vector_rep)
    • XPD (antisymmetric_op)
  • As part of refactoring, some helper functions in Mark's original code used by these functions have not been explicitly coded, they have been incorporated in the preceding functions. (These are XPSetNSingle, XPSquare, XPdeg).
  • Added basic tests for XPPauli and XPPauliList. Some tests are yet to be added for XPPauliList for above implemented functions.
  • Left TODOs for points to be discussed/yet to be implemented .

Highly appreciate your feedback!

@dhruvbhq dhruvbhq added the QAMP label Oct 31, 2022
@dhruvbhq dhruvbhq requested review from dsvandet and a user October 31, 2022 11:14
qiskit_qec/operators/base_xp_pauli.py Outdated Show resolved Hide resolved
@@ -104,6 +108,8 @@ def __init__(
matrix = nmatrix

self.matrix = matrix
self.precision = precision
# TODO should _num_paulis be renamed to _num_xppaulis in this and derived classes?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are separating the Pauli and XPPauli classes I would say it is better to change the name as you suggest.

qiskit_qec/operators/base_xp_pauli.py Show resolved Hide resolved
BaseXPPauli: _description_
"""

assert a.precision == b.precision, QiskitError(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in a "_"-method but a higher method compose which probably belongs in XPPauli and XPPauliList (different for each). Assertions have the nice property that they have zero impact with DEBUG is set correctly but some people feel that they should not be used for format requirements and are more to detect algorithm and internal faults.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment.
Replaced assert with if...raise.

"""(TODO improve doc): This is the equivalent of XPRound from Mark's
code. It converts the XPPauli operator into unique vector form, ie
phase_exp in Z modulo 2*precision, x in Z_2, z in Z modulo
precision."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add explicit examples ...

return np.sum(np.logical_or(self.x, self.z), axis=-1)

def is_diagonal(self):
"""_summary_"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs

@@ -196,6 +197,38 @@ def random_clifford(num_qubits, seed=None):
return Clifford(StabilizerTable(table, phase))


def random_xppauli(num_qubits, precision=None, seed=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add type hints

Args:
num_qubits (int): the number of qubits.
precision (int): Precision of XP operators. Must be an integer
greater than or equal to 2.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add explicit examples

# TODO
pass

def compose(self, other, qargs=None, front=False, inplace=False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type hints

from Mark's code. It returns the count of qubits where either z or x
component is nonzero."""
# TODO Since 'distance' has a specific meaning in QECCs, for now, the
# name 'weight' has been used for this function.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that weight is better than 'distance'

@dhruvbhq dhruvbhq self-assigned this Nov 10, 2022
@dhruvbhq
Copy link
Collaborator Author

In addition to implementing review comments, I've also added tests for XPPauliList with the new commits.

Copy link
Collaborator

@dsvandet dsvandet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ghost ghost merged commit 21ee5ce into Issue-257/XP_Formalism Nov 14, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants