mindquantum.algorithm.library

Circuit library

mindquantum.algorithm.library.amplitude_encoder(x, n_qubits)[source]

Quantum circuit for amplitude encoding

Note

the length of classic data ought to be the power of 2, otherwise will be filled up with 0 the vector should be normalized

Parameters
  • x (list[float] or numpy.array(list[float]) – the vector of data you want to encode, which should be normalized

  • n_qubits (int) – the number of qubits of the encoder circuit

Examples

>>> from mindquantum.algorithm.library import amplitude_encoder
>>> from mindquantum.simulator import Simulator
>>> sim = Simulator('projectq', 8)
>>> encoder, parameterResolver = amplitude_encoder([0.5, 0.5, 0.5, 0.5], 8)
>>> sim.apply_circuit(encoder, parameterResolver)
>>> print(sim.get_qs(True))
1/2¦00000000⟩
1/2¦01000000⟩
1/2¦10000000⟩
1/2¦11000000⟩
>>> sim.reset()
>>> encoder, parameterResolver = amplitude_encoder([0, 0, 0.5, 0.5, 0.5, 0.5], 8)
>>> sim.apply_circuit(encoder, parameterResolver)
>>> print(sim.get_qs(True))
1/2¦00100000⟩
1/2¦01000000⟩
1/2¦10100000⟩
1/2¦11000000⟩
mindquantum.algorithm.library.qft(qubits)[source]

Quantum fourier transform.

Note

Please refer Nielsen, M., & Chuang, I. (2010) for more information.

Parameters

qubits (list[int]) – Qubits you want to apply quantum fourier transform.

Examples

>>> from mindquantum.algorithm.library import qft
>>> print(qft([0, 1]).get_qs(ket=True))
1/2¦00⟩
1/2¦01⟩
1/2¦10⟩
1/2¦11⟩