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
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⟩