positions_to_pauli_string

positions_to_pauli_string#

iqm.qaoa.transforming_functions.positions_to_pauli_string(positions, num_qubits)[source]#

Create a string with the character “Z” on the specified positions and the character “I” elsewhere.

The string is intended to be used to construct a PauliList and from it a SparsePauliOp.

Parameters:
  • positions (set[int]) – Set of qubit indices where “Z” should be.

  • num_qubits (int) – Total number of qubits in the system (i.e., the length of the string).

Returns:

The Pauli string.

Raises:

ValueError – If any of the qubit indices is negative or too large (more than num_qubits-1).

Return type:

str