pytket.partition#

class pytket.partition.GraphColourMethod#

Enum for available methods to perform graph colouring.

Members:

Lazy : Does not build the graph before performing the colouring; partitions while iterating through the Pauli tensors in the input order.

LargestFirst : Builds the graph and then greedily colours by iterating through the vertices, with the highest degree first.

Exhaustive : Builds the graph and then systematically checks all possibilities until it finds a colouring with the minimum possible number of colours. Such colourings need not be unique. Exponential time in the worst case, but often runs much faster.

__init__(self: pytket.partition.GraphColourMethod, value: int) None#
property name#
class pytket.partition.MeasurementBitMap#

Maps Pauli tensors to Clifford circuit indices and bits required for measurement. A MeasurementBitMap belongs to a MeasurementSetup object, and dictates which bits are to be included in the measurement. As Clifford circuits may flip the parity of the corresponding Pauli tensor, the MeasurementBitMap optionally inverts the result.

__init__(self: pytket.partition.MeasurementBitMap, circ_index: int, bits: Sequence[int], invert: bool = False) None#

Constructs a MeasurementBitMap for some Clifford circuit index and bits, with an option to invert the result.

Parameters:
  • circ_index – which measurement circuit the measurement map refers to

  • bits – which bits are included in the measurement

  • invert – whether to flip the parity of the result

static from_dict(arg0: dict) pytket.partition.MeasurementBitMap#

Construct MeasurementBitMap instance from dict representation.

to_dict(self: pytket.partition.MeasurementBitMap) dict#

JSON-serializable dict representation of the MeasurementBitMap.

Returns:

dict representation of the MeasurementBitMap

property bits#

Bits to measure

property circ_index#

Clifford circuit index

property invert#

Whether result is inverted or not

class pytket.partition.MeasurementSetup#

Encapsulates an experiment in which the expectation value of an operator is to be measured via decomposition into QubitPauliStrings. Each tensor expectation value can be measured using shots. These values are then summed together with some weights to retrieve the desired operator expctation value.

__init__(self: pytket.partition.MeasurementSetup) None#

Constructs an empty MeasurementSetup object

add_measurement_circuit(self: pytket.partition.MeasurementSetup, circ: pytket.circuit.Circuit) None#

Add a Clifford circuit that rotates into some Pauli basis

add_result_for_term(self: pytket.partition.MeasurementSetup, term: pytket.pauli.QubitPauliString, result: pytket.partition.MeasurementBitMap) None#

Add a new Pauli string with a corresponding BitMap

static from_dict(arg0: dict) pytket.partition.MeasurementSetup#

Construct MeasurementSetup instance from dict representation.

to_dict(self: pytket.partition.MeasurementSetup) dict#

JSON-serializable dict representation of the MeasurementSetup.

Returns:

dict representation of the MeasurementSetup

verify(self: pytket.partition.MeasurementSetup) bool#

Checks that the strings to be measured correspond to the correct strings generated by the measurement circs. Checks for parity by comparing to the invert flag.

Returns:

True or False

property measurement_circs#

Clifford measurement circuits.

property results#

Map from Pauli strings to MeasurementBitMaps

class pytket.partition.PauliPartitionStrat#

Enum for available strategies to partition Pauli tensors.

Members:

NonConflictingSets : Build sets of Pauli tensors in which each qubit has the same Pauli or Pauli.I. Requires no additional CX gates for diagonalisation.

CommutingSets : Build sets of mutually commuting Pauli tensors. Requires O(n^2) CX gates to diagonalise.

__init__(self: pytket.partition.PauliPartitionStrat, value: int) None#
property name#
pytket.partition.measurement_reduction(strings: Sequence[pytket.pauli.QubitPauliString], strat: pytket.partition.PauliPartitionStrat, method: pytket.partition.GraphColourMethod = GraphColourMethod.Lazy, cx_config: pytket.circuit.CXConfigType = CXConfigType.Snake) pytket.partition.MeasurementSetup#

Automatically performs graph colouring and diagonalisation to reduce measurements required for Pauli strings.

Parameters:
  • strings – A list of QubitPauliString objects to be partitioned.

  • strat – The PauliPartitionStrat to use.

  • method – The GraphColourMethod to use.

  • cx_config – Whenever diagonalisation is required, use this configuration of CX gates

Returns:

a MeasurementSetup object

pytket.partition.term_sequence(strings: Sequence[pytket.pauli.QubitPauliString], strat: pytket.partition.PauliPartitionStrat = PauliPartitionStrat.CommutingSets, method: pytket.partition.GraphColourMethod = GraphColourMethod.Lazy) list[list[pytket.pauli.QubitPauliString]]#

Takes in a list of QubitPauliString objects and partitions them into mutually commuting sets according to some PauliPartitionStrat, then sequences in an arbitrary order.

Parameters:
  • tensors – A list of QubitPauliString objects to be sequenced. Assumes that each Pauli tensor is unique, and does not combine equivalent tensors.

  • strat – The PauliPartitionStrat to use. Defaults to CommutingSets.

  • method – The GraphColourMethod to use.

Returns:

a list of lists of QubitPauliString s