mindquantum.algorithm.nisq.IQPEncoding

View Source On Gitee
class mindquantum.algorithm.nisq.IQPEncoding(n_feature, first_rotation_gate=RZ, second_rotation_gate=RZ, num_repeats=1, prefix: str = '', suffix: str = '')[source]

General IQP Encoding.

For more information, please refer to Supervised learning with quantum-enhanced feature spaces.

Parameters
  • n_feature (int) – The number of feature of data you want to encode with IQPEncoding.

  • first_rotation_gate (ParameterGate) – One of the rotation gate RX, RY or RZ.

  • second_rotation_gate (ParameterGate) – One of the rotation gate RX, RY or RZ.

  • num_repeats (int) – Number of encoding iterations.

  • prefix (str) – The prefix of parameters. Default: ''.

  • suffix (str) – The suffix of parameters. Default: ''.

Examples

>>> import numpy as np
>>> from mindquantum.algorithm.nisq import IQPEncoding
>>> iqp = IQPEncoding(3)
>>> iqp.circuit
      ┏━━━┓ ┏━━━━━━━━━━━━┓
q0: ──┨ H ┠─┨ RZ(alpha0) ┠───■─────────────────────────────■─────────────────────────────────────────
      ┗━━━┛ ┗━━━━━━━━━━━━┛   ┃                             ┃
      ┏━━━┓ ┏━━━━━━━━━━━━┓ ┏━┻━┓ ┏━━━━━━━━━━━━━━━━━━━━━┓ ┏━┻━┓
q1: ──┨ H ┠─┨ RZ(alpha1) ┠─┨╺╋╸┠─┨ RZ(alpha0 * alpha1) ┠─┨╺╋╸┠───■─────────────────────────────■─────
      ┗━━━┛ ┗━━━━━━━━━━━━┛ ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━┛   ┃                             ┃
      ┏━━━┓ ┏━━━━━━━━━━━━┓                                     ┏━┻━┓ ┏━━━━━━━━━━━━━━━━━━━━━┓ ┏━┻━┓
q2: ──┨ H ┠─┨ RZ(alpha2) ┠─────────────────────────────────────┨╺╋╸┠─┨ RZ(alpha1 * alpha2) ┠─┨╺╋╸┠───
      ┗━━━┛ ┗━━━━━━━━━━━━┛                                     ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━┛
>>> iqp.circuit.params_name
['alpha0', 'alpha1', 'alpha2', 'alpha0 * alpha1', 'alpha1 * alpha2']
>>> iqp.circuit.params_name
>>> a = np.array([0, 1, 2])
>>> iqp.data_preparation(a)
array([0, 1, 2, 0, 2])
>>> iqp.circuit.get_qs(pr=iqp.data_preparation(a))
array([-0.28324704-0.21159186j, -0.28324704-0.21159186j,
        0.31027229+0.16950252j,  0.31027229+0.16950252j,
        0.02500938+0.35266773j,  0.02500938+0.35266773j,
        0.31027229+0.16950252j,  0.31027229+0.16950252j])
data_preparation(data)[source]

Prepare the classical data into suitable dimension for IQPEncoding.

The IQPEncoding ansatz provides an ansatz to encode classical data into quantum state.

Suppose the origin data has n features, then the output data will have 2n1 features, with first n features will be the original data. For m>n,

datam=datamndatamn1
Parameters

data ([list, numpy.ndarray]) – The classical data need to encode with IQPEncoding ansatz.

Returns

numpy.ndarray, the prepared data that is suitable for this ansatz.