C贸digo fuente para qiskit.circuit.library.data_preparation.zz_feature_map

# This code is part of Qiskit.
# (C) Copyright IBM 2017, 2020.
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Second-order Pauli-Z expansion circuit."""

from typing import Callable, List, Union, Optional
import numpy as np
from .pauli_feature_map import PauliFeatureMap

[documentos]class ZZFeatureMap(PauliFeatureMap): """Second-order Pauli-Z evolution circuit. For 3 qubits and 1 repetition and linear entanglement the circuit is represented by: .. parsed-literal:: 鈹屸攢鈹鈹鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹 H 鈹溾敜 U1(2.0*蠁(x[0])) 鈹溾攢鈹鈻犫攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈻犫攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹溾攢鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹も攲鈹鈹粹攢鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹愨攲鈹鈹粹攢鈹 鈹 H 鈹溾敜 U1(2.0*蠁(x[1])) 鈹溾敜 X 鈹溾敜 U1(2.0*蠁(x[0],x[1])) 鈹溾敜 X 鈹溾攢鈹鈻犫攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈻犫攢鈹 鈹溾攢鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹も敂鈹鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹樷敂鈹鈹鈹鈹樷攲鈹鈹粹攢鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹愨攲鈹鈹粹攢鈹 鈹 H 鈹溾敜 U1(2.0*蠁(x[2])) 鈹溾攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 X 鈹溾敜 U1(2.0*蠁(x[1],x[2])) 鈹溾敜 X 鈹 鈹斺攢鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹斺攢鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹樷敂鈹鈹鈹鈹 where ``蠁`` is a classical non-linear function, which defaults to ``蠁(x) = x`` if and ``蠁(x,y) = (pi - x)(pi - y)``. Examples: >>> from qiskit.circuit.library import ZZFeatureMap >>> prep = ZZFeatureMap(2, reps=1) >>> print(prep) 鈹屸攢鈹鈹鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_0: 鈹 H 鈹溾敜 U1(2.0*x[0]) 鈹溾攢鈹鈻犫攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈻犫攢鈹 鈹溾攢鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹も攲鈹鈹粹攢鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹愨攲鈹鈹粹攢鈹 q_1: 鈹 H 鈹溾敜 U1(2.0*x[1]) 鈹溾敜 X 鈹溾敜 U1(2.0*(pi - x[0])*(pi - x[1])) 鈹溾敜 X 鈹 鈹斺攢鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹樷敂鈹鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹樷敂鈹鈹鈹鈹 >>> from qiskit.circuit.library import EfficientSU2 >>> classifier = ZZFeatureMap(3) + EfficientSU2(3) >>> classifier.num_parameters 15 >>> classifier.parameters # 'x' for the data preparation, '胃' for the SU2 parameters ParameterView([ ParameterVectorElement(x[0]), ParameterVectorElement(x[1]), ParameterVectorElement(x[2]), ParameterVectorElement(胃[0]), ParameterVectorElement(胃[1]), ParameterVectorElement(胃[2]), ParameterVectorElement(胃[3]), ParameterVectorElement(胃[4]), ParameterVectorElement(胃[5]), ParameterVectorElement(胃[6]), ParameterVectorElement(胃[7]), ParameterVectorElement(胃[8]), ParameterVectorElement(胃[9]), ParameterVectorElement(胃[10]), ParameterVectorElement(胃[11]), ParameterVectorElement(胃[12]), ParameterVectorElement(胃[13]), ParameterVectorElement(胃[14]), ParameterVectorElement(胃[15]), ParameterVectorElement(胃[16]), ParameterVectorElement(胃[17]), ParameterVectorElement(胃[18]), ParameterVectorElement(胃[19]), ParameterVectorElement(胃[20]), ParameterVectorElement(胃[21]), ParameterVectorElement(胃[22]), ParameterVectorElement(胃[23]) ]) >>> classifier.count_ops() OrderedDict([('ZZFeatureMap', 1), ('EfficientSU2', 1)]) """ def __init__( self, feature_dimension: int, reps: int = 2, entanglement: Union[str, List[List[int]], Callable[[int], List[int]]] = "full", data_map_func: Optional[Callable[[np.ndarray], float]] = None, parameter_prefix: str = "x", insert_barriers: bool = False, name: str = "ZZFeatureMap", ) -> None: """Create a new second-order Pauli-Z expansion. Args: feature_dimension: Number of features. reps: The number of repeated circuits, has a min. value of 1. entanglement: Specifies the entanglement structure. Refer to :class:`~qiskit.circuit.library.NLocal` for detail. data_map_func: A mapping function for data x. parameter_prefix: The prefix used if default parameters are generated. insert_barriers: If True, barriers are inserted in between the evolution instructions and hadamard layers. Raises: ValueError: If the feature dimension is smaller than 2. """ if feature_dimension < 2: raise ValueError( "The ZZFeatureMap contains 2-local interactions and cannot be " f"defined for less than 2 qubits. You provided {feature_dimension}." ) super().__init__( feature_dimension=feature_dimension, reps=reps, entanglement=entanglement, paulis=["Z", "ZZ"], data_map_func=data_map_func, parameter_prefix=parameter_prefix, insert_barriers=insert_barriers, name=name, )