pyquil.paulis

Module for working with Pauli algebras.

pyquil.paulis.ID()

The identity Pauli Term.

class pyquil.paulis.PauliSum(terms)

Bases: object

A sum of one or more PauliTerms.

get_qubits()

The support of all the operators in the PauliSum object.

Returns:A list of all the qubits in the sum of terms.
Return type:list
simplify()

Simplifies the sum of Pauli operators according to Pauli algebra rules.

class pyquil.paulis.PauliTerm(op, index, coefficient=1.0)

Bases: object

A term is a product of Pauli operators operating on different qubits.

copy()

Properly creates a new PauliTerm, with a completely new dictionary of operators

classmethod from_list(terms_list, coefficient=1.0)

Allocates a Pauli Term from a list of operators and indices. This is more efficient than multiplying together individual terms.

Parameters:terms_list (list) – A list of tuples, e.g. [(“X”, 0), (“Y”, 1)]
Returns:PauliTerm
get_qubits()

Gets all the qubits that this PauliTerm operates on.

id()
Returns the unique identifier string for the PauliTerm (ignoring the coefficient).
Used in the simplify method of PauliSum.
Returns:The unique identifier for this term.
Return type:string
exception pyquil.paulis.UnequalLengthWarning(*args, **kwargs)

Bases: exceptions.Warning

pyquil.paulis.ZERO()

The zero Pauli Term.

pyquil.paulis.check_commutation(pauli_list, pauli_two)

Check if commuting a PauliTerm commutes with a list of other terms by natural calculation. Derivation similar to arXiv:1405.5749v2 fo the check_commutation step in the Raesi, Wiebe, Sanders algorithm (arXiv:1108.4318, 2011).

Parameters:
  • pauli_list (list) – A list of PauliTerm objects
  • pauli_two_term (PauliTerm) – A PauliTerm object
Returns:

True if pauli_two object commutes with pauli_list, False otherwise

Return type:

bool

pyquil.paulis.commuting_sets(pauli_terms, nqubits)

Gather the Pauli terms of pauli_terms variable into commuting sets

Uses algorithm defined in (Raeisi, Wiebe, Sanders, arXiv:1108.4318, 2011) to find commuting sets. Except uses commutation check from arXiv:1405.5749v2

Parameters:pauli_terms (PauliSum) – A PauliSum object
Returns:List of lists where each list contains a commuting set
Return type:list
pyquil.paulis.exponential_map(term)

Creates map alpha -> exp(-1j*alpha*term) represented as a Program.

Parameters:term (PauliTerm) – Tests is a PauliTerm is the identity operator
Returns:Program
Return type:Program
pyquil.paulis.exponentiate(term)

Creates a pyQuil program that simulates the unitary evolution exp(-1j * term)

Parameters:term (PauliTerm) – Tests is a PauliTerm is the identity operator
Returns:A Program object
Return type:Program
pyquil.paulis.is_identity(term)

Check if Pauli Term is a scalar multiple of identity

Parameters:term (PauliTerm) – A PauliTerm object
Returns:True if the PauliTerm is a scalar multiple of identity, false otherwise
Return type:bool
pyquil.paulis.is_zero(pauli_object)

Tests to see if a PauliTerm or PauliSum is zero.

Parameters:pauli_object – Either a PauliTerm or PauliSum
Returns:True if PauliTerm is zero, False otherwise
Return type:bool
pyquil.paulis.sI(q)

A function that returns the identity operator on a particular qubit.

Parameters:qubit_index (int) – The index of the qubit
Returns:A PauliTerm object
Return type:PauliTerm
pyquil.paulis.sX(q)

A function that returns the sigma_X operator on a particular qubit.

Parameters:qubit_index (int) – The index of the qubit
Returns:A PauliTerm object
Return type:PauliTerm
pyquil.paulis.sY(q)

A function that returns the sigma_Y operator on a particular qubit.

Parameters:qubit_index (int) – The index of the qubit
Returns:A PauliTerm object
Return type:PauliTerm
pyquil.paulis.sZ(q)

A function that returns the sigma_Z operator on a particular qubit.

Parameters:qubit_index (int) – The index of the qubit
Returns:A PauliTerm object
Return type:PauliTerm
pyquil.paulis.suzuki_trotter(trotter_order, trotter_steps)

Generate trotterization coefficients for a given number of Trotter steps.

U = exp(A + B) is approximated as exp(w1*o1)exp(w2*o2)… This method returns a list [(w1, o1), (w2, o2), … , (wm, om)] of tuples where o=0 corresponds to the A operator, o=1 corresponds to the B operator, and w is the coefficient in the exponential. For example, a second order Suzuki-Trotter approximation to exp(A + B) results in the following [(0.5/trotter_steps, 0), (1/trotteri_steps, 1), (0.5/trotter_steps, 0)] * trotter_steps.

Parameters:
  • trotter_order (int) – order of Suzuki-Trotter approximation
  • trotter_steps (int) – number of steps in the approximation
Returns:

List of tuples corresponding to the coefficient and operator type: o=0 is A and o=1 is B.

Return type:

list

pyquil.paulis.term_with_coeff(term, coeff)

Change the coefficient of a PauliTerm.

Parameters:
  • term (PauliTerm) – A PauliTerm object
  • coeff (Number) – The coefficient to set on the PauliTerm
Returns:

A new PauliTerm that duplicates term but sets coeff

Return type:

PauliTerm

pyquil.paulis.trotterize(first_pauli_term, second_pauli_term, trotter_order=1, trotter_steps=1)

Create a Quil program that approximates exp( (A + B)t) where A and B are PauliTerm operators.

Parameters:
  • first_pauli_term (PauliTerm) – PauliTerm denoted A
  • second_pauli_term (PauliTerm) – PauliTerm denoted B
  • trotter_order (int) – Optional argument indicating the Suzuki-Trotter approximation order–only accepts orders 1, 2, 3, 4.
  • trotter_steps (int) – Optional argument indicating the number of products to decompose the exponential into.
Returns:

Quil program

Return type:

Program