pyqpanda_alg.QAE.QAE

Classes

QAE

This class provides a framework for original Quantum Amplitude Estimation(QAE) algorithm [1].

IQAE

This class provides a framework for Iterative Quantum Amplitude Estimation(IQAE) algorithm [2].

Module Contents

class pyqpanda_alg.QAE.QAE.QAE(operator_in=None, qnumber: int = 0, res_index: int | pyqpanda_alg.plugin.List[int] = -1, epsilon: float = 0.001, target_state: str = '1')

This class provides a framework for original Quantum Amplitude Estimation(QAE) algorithm [1].

Parameters

operator_in : callable f(qubits)

Operator/Circuit of the estimated qubits state.

qnumber : int

The number of all qubits used in circuit.

res_index : int, list

The index of the estimated qubit(s).

epsilon : float

Estimated precision, i.e. the minimum error.

target_state : str

Estimated target state.

References

[1] Brassard G, Hoyer P, Mosca M, et al. Quantum amplitude amplification and estimation[J]. Contemporary Mathematics, 2002, 305: 53-74.

>>> from pyqpanda_alg import QAE
>>> import numpy as np
>>> from pyqpanda3.core import *
>>> def create_cir(qlist):
>>>     cir = QCircuit()
>>>     cir << RY(qlist[0], np.pi / 3) << X(qlist[1]).control(qlist[0])
>>>     return cir
>>> W = QAE.QAE(operator_in=create_cir, qnumber=2, epsilon=0.01, res_index=[0, 1], target_state='11').run()
>>> print(W)
0.24294862790338914
operator = None
epsilon = 0.001
qnumber = 0
machine_type = 'CPU'
n_anc
max_anc_qubits = 14
res_index = -1
target_state = '1'
run()

Run the quantum amplitude estimation algorithm.

Returns

prob : float

A probability value as the amplitude estimation result.

Examples

An example for implementing an amplitude estimation for target state ‘11’ of the following circuit.

          ┌────────────┐
q_0:  |0>─┤RY(1.047198)├ ─■─
          └────────────┘ ┌┴┐
q_1:  |0>─────────────── ┤X├
                         └─┘
>>> from pyqpanda_alg import QAE
>>> import numpy as np
>>> from pyqpanda3.core import *
>>> def create_cir(qlist):
>>>     cir = QCircuit()
>>>     cir << RY(qlist[0], np.pi / 3) << X(qlist[1]).control(qlist[0])
>>>     return cir
>>> W = QAE.QAE(operator_in=create_cir, qnumber=2, epsilon=0.01, res_index=[0, 1], target_state='11').run()
>>> print(W)
0.24294862790338914
class pyqpanda_alg.QAE.QAE.IQAE(operator_in=None, qnumber: int = 0, res_index: int = -1, epsilon: float = 0.001)

This class provides a framework for Iterative Quantum Amplitude Estimation(IQAE) algorithm [2]. Estimated target state is \(|1\rangle\).

Parameters

operator_in : callable f(qubits)

Operator/Circuit of the estimated qubits state.

qnumber : int

The number of all qubits used in circuit.

res_index : int

The index of the estimated qubit.

epsilon : float

Estimated precision, i.e. the minimum error.

References

[2] Grinko, D., Gacon, J., Zoufal, C. et al. Iterative quantum amplitude estimation. npj Quantum Inf 7, 52 (2021). https://doi.org/10.1038/s41534-021-00379-1

>>> from pyqpanda_alg import QAE
>>> import numpy as np
>>> from pyqpanda3.core import *
>>> def create_cir(qlist):
>>>     cir = QCircuit()
>>>     cir << RY(qlist[0], np.pi / 3) << X(qlist[1]).control(qlist[0])
>>>     return cir
>>> W = QAE.IQAE(operator_in=create_cir, qnumber=2, epsilon=0.01, res_index=-1).run()
>>> print(W)
0.25735228001322236
epsilon = 0.001
alpha = 0.05
method = 'cher'
ratio = 2.0
qnumber = 0
res_index = -1
machine_type = 'CPU'
n_sum = 0
qlist
clist
operatorA = None
a_l = 0
a_u = 0
N_max
draw = False
run()

Run the iterative quantum amplitude estimation algorithm.

Returns

prob : float

A probability value as the iterative amplitude estimation result.

Examples

An example for implementing an iterative amplitude estimation for qubit q_1 of the following circuit.

          ┌────────────┐
q_0:  |0>─┤RY(1.047198)├ ─■─
          └────────────┘ ┌┴┐
q_1:  |0>─────────────── ┤X├
                         └─┘
>>> from pyqpanda_alg import QAE
>>> import numpy as np
>>> from pyqpanda3.core import *
>>> def create_cir(qlist):
>>>     cir = QCircuit()
>>>     cir << RY(qlist[0], np.pi / 3) << X(qlist[1]).control(qlist[0])
>>>     return cir
>>> W = QAE.IQAE(operator_in=create_cir, qnumber=2, epsilon=0.01, res_index=-1).run()
>>> print(W)
0.25735228001322236