qml.pauli.binary_to_pauli

binary_to_pauli(binary_vector, wire_map=None)[source]

Converts a binary vector of even dimension to an Observable instance.

This functions follows the convention that the first half of binary vector components specify PauliX placements while the last half specify PauliZ placements.

Parameters
  • binary_vector (Union[list, tuple, array]) – binary vector of even dimension representing a unique Pauli word

  • wire_map (dict) – dictionary containing all wire labels used in the Pauli word as keys, and unique integer labels as their values

Returns

The Pauli word corresponding to the input binary vector. Note that if a zero vector is input, then the resulting Pauli word will be an Identity instance. If new operator arithmetic is enabled via enable_new_opmath(), a Prod will be returned, else a Tensor will be returned.

Return type

Union[Tensor, Prod]

Raises

TypeError – if length of binary vector is not even, or if vector does not have strictly binary components

Example

If wire_map is unspecified, the Pauli operations follow the same enumerations as the vector components, i.e., the i and N+i components specify the Pauli operation on wire i,

>>> binary_to_pauli([0,1,1,0,1,0])
Tensor(Y(1), X(2))

An arbitrary labelling can be assigned by using wire_map:

>>> wire_map = {'a': 0, 'b': 1, 'c': 2}
>>> binary_to_pauli([0,1,1,0,1,0], wire_map=wire_map)
Tensor(Y('b'), X('c'))

Note that the values of wire_map, if specified, must be 0,1,..., N, where N is the dimension of the vector divided by two, i.e., list(wire_map.values()) must be list(range(len(binary_vector)/2)).