qiskit.circuit.library.pauli_feature_map
qiskit.circuit.library.pauli_feature_map(feature_dimension, reps=2, entanglement='full', alpha=2.0, paulis=None, data_map_func=None, parameter_prefix='x', insert_barriers=False, name='PauliFeatureMap')
The Pauli expansion circuit.
The Pauli expansion circuit is a data encoding circuit that transforms input data , where is the feature_dimension, as
Here, is a set of qubit indices that describes the connections in the feature map, is a set containing all these index sets, and . Per default the data-mapping is
The possible connections can be set using the entanglement and paulis arguments. For example, for single-qubit rotations and two-qubit interactions between all qubit pairs, we can set:
circuit = pauli_feature_map(..., paulis=["Z", "YY"], entanglement="full")which will produce blocks of the form
┌───┐┌─────────────┐┌──────────┐ ┌───────────┐
┤ H ├┤ P(2.0*x[0]) ├┤ RX(pi/2) ├──■──────────────────────────────────────■──┤ RX(-pi/2) ├
├───┤├─────────────┤├──────────┤┌─┴─┐┌────────────────────────────────┐┌─┴─┐├───────────┤
┤ H ├┤ P(2.0*x[1]) ├┤ RX(pi/2) ├┤ X ├┤ P(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├┤ RX(-pi/2) ├
└───┘└─────────────┘└──────────┘└───┘└────────────────────────────────┘└───┘└───────────┘The circuit contains reps repetitions of this transformation.
Please refer to z_feature_map() for the case of single-qubit Pauli- rotations and to zz_feature_map() for the single- and two-qubit Pauli- rotations.
Parameters
- feature_dimension (int) – Number of qubits in the circuit.
- reps (int) – The number of times the evolution layers are repeated.
- entanglement (str |Mapping[int, Sequence[Sequence[int]]] | Callable[[int], str |Mapping[int, Sequence[Sequence[int]]]]) – Specifies the entanglement structure. Can be a string (
'full','linear','reverse_linear','circular'or'sca') or can be a dictionary where the keys represent the number of qubits and the values are list of integer-pairs specifying the indices of qubits that are entangled with one another, for example:{1: [(0,), (2,)], 2: [(0,1), (2,0)]}or can be aCallable[[int], Union[str | Dict[...]]]to return an entanglement specific for a repetition. - alpha (float) – The Pauli rotation factor, multiplicative to the pauli rotations.
- paulis (list[str] | None) – A list of strings for to-be-used paulis. If None are provided,
['Z', 'ZZ']will be used. - data_map_func (Callable[[Parameter], ParameterExpression] | None) – A mapping function for the data
xwhich can be supplied to override the default mapping. - parameter_prefix (str) – The prefix used if default parameters are generated.
- insert_barriers (bool) – If
True, barriers are inserted in between the evolution instructions and Hadamard layers. - name (str) – The name of the circuit.
Returns
A quantum circuit implementing the Pauli feature map.
Return type
Examples
>>> prep = pauli_feature_map(2, reps=1, paulis=["ZZ"])
>>> print(prep)
┌───┐
q_0: ┤ H ├──■──────────────────────────────────────■──
├───┤┌─┴─┐┌────────────────────────────────┐┌─┴─┐
q_1: ┤ H ├┤ X ├┤ P(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├
└───┘└───┘└────────────────────────────────┘└───┘>>> prep = pauli_feature_map(2, reps=1, paulis=["Z", "XX"])
>>> print(prep)
┌───┐┌─────────────┐┌───┐ ┌───┐
q_0: ┤ H ├┤ P(2.0*x[0]) ├┤ H ├──■──────────────────────────────────────■──┤ H ├
├───┤├─────────────┤├───┤┌─┴─┐┌────────────────────────────────┐┌─┴─┐├───┤
q_1: ┤ H ├┤ P(2.0*x[1]) ├┤ H ├┤ X ├┤ P(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├┤ H ├
└───┘└─────────────┘└───┘└───┘└────────────────────────────────┘└───┘└───┘>>> prep = pauli_feature_map(2, reps=1, paulis=["ZY"])
>>> print(prep)
┌───┐┌──────────┐ ┌───────────┐
q_0: ┤ H ├┤ RX(pi/2) ├──■──────────────────────────────────────■──┤ RX(-pi/2) ├
├───┤└──────────┘┌─┴─┐┌────────────────────────────────┐┌─┴─┐└───────────┘
q_1: ┤ H ├────────────┤ X ├┤ P(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├─────────────
└───┘ └───┘└────────────────────────────────┘└───┘>>> from qiskit.circuit.library import efficient_su2
>>> prep = pauli_feature_map(3, reps=3, paulis=["Z", "YY", "ZXZ"])
>>> wavefunction = efficient_su2(3)
>>> classifier = prep.compose(wavefunction)
>>> classifier.num_parameters
27
>>> classifier.count_ops()
OrderedDict([('cx', 39), ('rx', 36), ('u1', 21), ('h', 15), ('ry', 12), ('rz', 12)])References:
[1] Havlicek et al. Supervised learning with quantum enhanced feature spaces, Nature 567, 209-212 (2019).