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¦00000001⟩ 1/2¦00000010⟩ 1/2¦00000011⟩ >>> 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¦00000010⟩ 1/2¦00000011⟩ -1/2¦00000100⟩ 1/2¦00000101⟩
- mindquantum.algorithm.library.bitphaseflip_operator(phase_inversion_index, n_qubits)[source]
This operator generate a circuit that can flip the sign of any calculation bases.
- Parameters
Examples
>>> from mindquantum.core.circuit import Circuit >>> from mindquantum import UN, H, Z >>> from mindquantum.algorithm.library import bitphaseflip_operator >>> circuit = Circuit() >>> circuit += UN(H, 3) >>> circuit += bitphaseflip_operator([1, 3], 3) >>> print(circuit.get_qs(ket=True)) √2/4¦000⟩ -√2/4¦001⟩ √2/4¦010⟩ -√2/4¦011⟩ √2/4¦100⟩ √2/4¦101⟩ √2/4¦110⟩ √2/4¦111⟩
- Returns
Circuit, the bit phase flip circuit.
- mindquantum.algorithm.library.general_ghz_state(qubits)[source]
Circuit that prepare a general GHZ State based on zero state.
Examples
>>> from mindquantum.algorithm.library import general_ghz_state >>> print(general_ghz_state(range(3)).get_qs(ket=True)) √2/2¦000⟩ √2/2¦111⟩ >>> print(general_ghz_state([1, 2]).get_qs(ket=True)) √2/2¦000⟩ √2/2¦110⟩
- Returns
Circuit, circuit that can prepare ghz state.
- mindquantum.algorithm.library.general_w_state(qubits)[source]
General W State.
Note
Please refer https://quantumcomputing.stackexchange.com/questions/4350/general-construction-of-w-n-state.
Examples
>>> from mindquantum.algorithm.library import general_w_state >>> print(general_w_state(range(3)).get_qs(ket=True)) 0.5773502691896257¦001⟩ 0.5773502691896258¦010⟩ 0.5773502691896257¦100⟩
- Returns
Circuit, circuit that can prepare w state.
- mindquantum.algorithm.library.qft(qubits)[source]
Quantum fourier transform.
Note
Please refer Nielsen, M., & Chuang, I. (2010) for more information.
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⟩
- Returns
Circuit, circuit that can do fourier transform.