Skip to content

Commit

Permalink
First-round-of-review
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Nov 17, 2019
1 parent c33c948 commit 7761a5b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions pyquil/paulis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import copy

from typing import Callable, Dict, FrozenSet, Iterable, Iterator, List, Optional, Tuple, Union
from typing import Sequence as SequenceT

from pyquil.quilatom import QubitPlaceholder

Expand All @@ -33,8 +34,9 @@
from collections.abc import Sequence
import warnings

NumberT = Union[int, float, complex]
PauliT = Union['PauliTerm', 'PauliSum', NumberT]
ExpressionValueDesignator = Union[int, float, complex]
PauliDesignator = Union['PauliTerm', 'PauliSum']
PauliT = Union[PauliDesignator, ExpressionValueDesignator]

PAULI_OPS = ["X", "Y", "Z", "I"]
PAULI_PROD = {'ZZ': 'I', 'YY': 'I', 'XX': 'I', 'II': 'I',
Expand Down Expand Up @@ -73,7 +75,7 @@ class PauliTerm(object):
"""A term is a product of Pauli operators operating on different qubits.
"""

def __init__(self, op: str, index: int, coefficient: NumberT = 1.0):
def __init__(self, op: str, index: int, coefficient: ExpressionValueDesignator = 1.0):
""" Create a new Pauli Term with a Pauli operator at a particular index and a leading
coefficient.
Expand Down Expand Up @@ -206,7 +208,7 @@ def _multiply_factor(self, factor: str, index: int) -> 'PauliTerm':

return new_term

def __mul__(self, term: PauliT) -> Union['PauliTerm', 'PauliSum']:
def __mul__(self, term: PauliT) -> PauliDesignator:
"""Multiplies this Pauli Term with another PauliTerm, PauliSum, or number according to the
Pauli algebra rules.
Expand Down Expand Up @@ -505,7 +507,7 @@ class PauliSum(object):
"""A sum of one or more PauliTerms.
"""

def __init__(self, terms: List[PauliTerm]):
def __init__(self, terms: SequenceT[PauliTerm]):
"""
:param Sequence terms: A Sequence of PauliTerms.
"""
Expand Down Expand Up @@ -684,7 +686,7 @@ def simplify(self) -> 'PauliSum':
"""
return simplify_pauli_sum(self)

def get_programs(self) -> Tuple[List[Program], List[NumberT]]:
def get_programs(self) -> Tuple[List[Program], List[ExpressionValueDesignator]]:
"""
Get a Pyquil Program corresponding to each term in the PauliSum and a coefficient
for each program
Expand Down Expand Up @@ -751,7 +753,7 @@ def simplify_pauli_sum(pauli_sum: PauliSum) -> PauliSum:
return PauliSum(terms)


def check_commutation(pauli_list: List[PauliTerm], pauli_two: PauliTerm) -> bool:
def check_commutation(pauli_list: SequenceT[PauliTerm], pauli_two: PauliTerm) -> bool:
"""
Check if commuting a PauliTerm commutes with a list of other terms by natural calculation.
Uses the result in Section 3 of arXiv:1405.5749v2, modified slightly here to check for the
Expand Down Expand Up @@ -808,7 +810,7 @@ def commuting_sets(pauli_terms: PauliSum) -> List[List[PauliTerm]]:
return groups


def is_identity(term: Union['PauliTerm', 'PauliSum']) -> bool:
def is_identity(term: PauliDesignator) -> bool:
"""
Tests to see if a PauliTerm or PauliSum is a scalar multiple of identity
Expand Down Expand Up @@ -989,8 +991,8 @@ def is_zero(pauli_object: Union[PauliTerm, PauliSum]) -> bool:
raise TypeError("is_zero only checks PauliTerms and PauliSum objects!")


def trotterize(first_pauli_term: PauliTerm, second_pauli_term: PauliTerm, trotter_order: Optional[int] = 1,
trotter_steps: Optional[int] = 1) -> Program:
def trotterize(first_pauli_term: PauliTerm, second_pauli_term: PauliTerm, trotter_order: int = 1,
trotter_steps: int = 1) -> Program:
"""
Create a Quil program that approximates exp( (A + B)t) where A and B are
PauliTerm operators.
Expand Down

0 comments on commit 7761a5b

Please sign in to comment.