Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

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.

Returns

Circuit, the parameterized quantum circuit that do amplitude encoder. ParameterResolver, the parameter for parameterized quantum circuit to do amplitude encoder.

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]

Generate a circuit that can flip the sign of any calculation bases.

Parameters
  • phase_inversion_index (list[int]) – Index of calculation bases want to flip phase.

  • n_qubits (int) – Total number of qubits.

Examples

>>> from mindquantum.core.circuit import Circuit, UN
>>> from mindquantum.core.gates import 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.

The GHZ State is defined as the equality superposition of three zeros state and three ones state:

Here in this API, we can create a general GHZ state on arbitrary sub qubits of any total qubits.

Parameters

qubits (list[int]) – Qubits you want to apply general GHZ 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.

The W State is defined as the equality superposition of bases that only one qubit is in |1 while others qubits are in |0. For example, a three qubits W state is defined as:

|W=(|001+|010+|100)/(3)

Here in this API, we can define a W state on any sub hilbert space of any total number qubits.

Parameters

qubits (list[int]) – Qubits you want to apply general W 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 (QFT).

The function of the quantum Fourier transform is similar to that of the classical Fourier transform.

Note

Please refer to 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⟩
Returns

Circuit, circuit that can do fourier transform.