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 viaenable_new_opmath()
, aProd
will be returned, else aTensor
will be returned.- Return type
- 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., thei
andN+i
components specify the Pauli operation on wirei
,>>> 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 be0,1,..., N
, whereN
is the dimension of the vector divided by two, i.e.,list(wire_map.values())
must belist(range(len(binary_vector)/2))
.