C贸digo fuente para qiskit.circuit.library.data_preparation.z_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.

"""Create a new first-order Pauli-Z expansion circuit."""

from typing import Callable, Optional
import numpy as np

from .pauli_feature_map import PauliFeatureMap


[documentos]class ZFeatureMap(PauliFeatureMap): """The first order Pauli Z-evolution circuit. On 3 qubits and with 2 repetitions the circuit is represented by: .. parsed-literal:: 鈹屸攢鈹鈹鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹愨攲鈹鈹鈹鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹 H 鈹溾敜 U1(2.0*x[0]) 鈹溾敜 H 鈹溾敜 U1(2.0*x[0]) 鈹 鈹溾攢鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹も敎鈹鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹 H 鈹溾敜 U1(2.0*x[1]) 鈹溾敜 H 鈹溾敜 U1(2.0*x[1]) 鈹 鈹溾攢鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹も敎鈹鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹 H 鈹溾敜 U1(2.0*x[2]) 鈹溾敜 H 鈹溾敜 U1(2.0*x[2]) 鈹 鈹斺攢鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹樷敂鈹鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 This is a sub-class of :class:`~qiskit.circuit.library.PauliFeatureMap` where the Pauli strings are fixed as `['Z']`. As a result the first order expansion will be a circuit without entangling gates. Examples: >>> prep = ZFeatureMap(3, reps=3, insert_barriers=True) >>> print(prep) 鈹屸攢鈹鈹鈹 鈻 鈹屸攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈻 鈹屸攢鈹鈹鈹 鈻 鈹屸攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈻 鈹屸攢鈹鈹鈹 鈻 鈹屸攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_0: 鈹 H 鈹溾攢鈻戔攢鈹 U1(2.0*x[0]) 鈹溾攢鈻戔攢鈹 H 鈹溾攢鈻戔攢鈹 U1(2.0*x[0]) 鈹溾攢鈻戔攢鈹 H 鈹溾攢鈻戔攢鈹 U1(2.0*x[0]) 鈹 鈹溾攢鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_1: 鈹 H 鈹溾攢鈻戔攢鈹 U1(2.0*x[1]) 鈹溾攢鈻戔攢鈹 H 鈹溾攢鈻戔攢鈹 U1(2.0*x[1]) 鈹溾攢鈻戔攢鈹 H 鈹溾攢鈻戔攢鈹 U1(2.0*x[1]) 鈹 鈹溾攢鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹 鈻 鈹溾攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_2: 鈹 H 鈹溾攢鈻戔攢鈹 U1(2.0*x[2]) 鈹溾攢鈻戔攢鈹 H 鈹溾攢鈻戔攢鈹 U1(2.0*x[2]) 鈹溾攢鈻戔攢鈹 H 鈹溾攢鈻戔攢鈹 U1(2.0*x[2]) 鈹 鈹斺攢鈹鈹鈹 鈻 鈹斺攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈻 鈹斺攢鈹鈹鈹 鈻 鈹斺攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈻 鈹斺攢鈹鈹鈹 鈻 鈹斺攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 >>> data_map = lambda x: x[0]*x[0] + 1 # note: input is an array >>> prep = ZFeatureMap(3, reps=1, data_map_func=data_map) >>> print(prep) 鈹屸攢鈹鈹鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_0: 鈹 H 鈹溾敜 U1(2.0*x[0]**2 + 2.0) 鈹 鈹溾攢鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_1: 鈹 H 鈹溾敜 U1(2.0*x[1]**2 + 2.0) 鈹 鈹溾攢鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_2: 鈹 H 鈹溾敜 U1(2.0*x[2]**2 + 2.0) 鈹 鈹斺攢鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 >>> classifier = ZFeatureMap(3, reps=1) + RY(3, reps=1) >>> print(classifier) 鈹屸攢鈹鈹鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹愨攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹屸攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_0: 鈹 H 鈹溾敜 U1(2.0*x[0]) 鈹溾敜 RY(胃[0]) 鈹溾攢鈻犫攢鈹鈻犫攢鈹 RY(胃[3]) 鈹溾攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹溾攢鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹 鈹 鈹斺攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹樷攲鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_1: 鈹 H 鈹溾敜 U1(2.0*x[1]) 鈹溾敜 RY(胃[1]) 鈹溾攢鈻犫攢鈹鈹尖攢鈹鈹鈹鈹鈹鈻犫攢鈹鈹鈹鈹鈹鈹 RY(胃[4]) 鈹 鈹溾攢鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹も敎鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹 鈹 鈹溾攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 q_2: 鈹 H 鈹溾敜 U1(2.0*x[2]) 鈹溾敜 RY(胃[2]) 鈹溾攢鈹鈹鈹鈻犫攢鈹鈹鈹鈹鈹鈻犫攢鈹鈹鈹鈹鈹鈹 RY(胃[5]) 鈹 鈹斺攢鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹樷敂鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 鈹斺攢鈹鈹鈹鈹鈹鈹鈹鈹鈹鈹 """ def __init__( self, feature_dimension: int, reps: int = 2, data_map_func: Optional[Callable[[np.ndarray], float]] = None, parameter_prefix: str = "x", insert_barriers: bool = False, name: str = "ZFeatureMap", ) -> None: """Create a new first-order Pauli-Z expansion circuit. Args: feature_dimension: The number of features reps: The number of repeated circuits. Defaults to 2, has a minimum value of 1. data_map_func: A mapping function for data x which can be supplied to override the default mapping from :meth:`self_product`. 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. """ super().__init__( feature_dimension=feature_dimension, paulis=["Z"], reps=reps, data_map_func=data_map_func, parameter_prefix=parameter_prefix, insert_barriers=insert_barriers, name=name, )