mindquantum.algorithm.nisq.QuantumNeuron
- class mindquantum.algorithm.nisq.QuantumNeuron(weight, gamma=1, bias=0, input_qubits=None, output_qubit=None, ancilla_qubit=None)[source]
A quantum neuron implementation based on RUS (Repeat-Until-Success) strategy, simulating classical neuron behavior and activation functions through quantum circuits.
For more details, see Quantum neuron: an elementary building block for machine learning on quantum computers.
Working principle: - Uses RUS circuit, repeatedly executing quantum circuits until target measurement is obtained - Measurement result '0' indicates successful application of non-linear function rotation - Measurement result '1' triggers recovery operation and repeats until success
Note
Based on empirical testing, the RUS circuit requires at least one failure (measurement '1') followed by a success (measurement '0') to correctly apply the non-linear function.
The recovery rotation angle in the original paper (arXiv:1711.11240) is RY(-π/2), but our implementation uses RY(π/2) based on experimental validation. Users are advised to carefully verify the behavior in their specific use cases.
- Parameters
weight (Union[List[float], np.ndarray]) – List of weights or numpy array. Length must equal number of input qubits, each weight corresponds to an input qubit.
gamma (Union[int, float]) – Scaling factor to adjust the weight impact. Default: 1
input_qubits (Optional[List[int]]) – List of qubit indices used as inputs. If None, will use [0, 1, …, len(weight)-1]. Default: None
output_qubit (Optional[int]) – Index of the qubit which is the output of the neuron. If None, will be set to ancilla_qubit + 1. Default: None
ancilla_qubit (Optional[int]) – Index of the auxiliary qubit used for computation. If None, will be set to len(input_qubits) + 1. Default: None
Examples
>>> from mindquantum.simulator import Simulator >>> from mindquantum import Circuit, H,X >>> # Create 2-qubit input state >>> circ = Circuit() >>> circ += H.on(0) >>> circ += H.on(1) >>> sim = Simulator('mqvector', 4) >>> sim.apply_circuit(circ) >>> qn = QuantumNeuron(weight=[1, 1], input_qubits=[0, 1], output_qubit=3, ancilla_qubit=2) >>> # Repeat quantum neuron circuit until success >>> while True: >>> result = sim.apply_circuit(qn.circuit) >>> if next(iter(result.data))[0] == '1': >>> sim.apply_circuit(qn.recovery_circuit) >>> else: >>> print("Non-linear function rotation successfully applied to output qubit") >>> break
- property circuit: mindquantum.core.circuit.circuit.Circuit
The quantum circuit of the quantum neuron.
- Returns
The quantum circuit of the quantum neuron
- Return type
- property recovery_circuit: mindquantum.core.circuit.circuit.Circuit
The recovery circuit when measurement result is '1'.
This circuit applies a π/2 rotation around Y-axis on the output qubit to recover from an unsuccessful measurement result.
Note
While the original paper (arXiv:1711.11240) suggests using a RY(-π/2) rotation, our implementation uses RY(π/2) based on experimental validation. Users should verify this behavior in their specific applications.
- Returns
Circuit, A quantum circuit for recovery operation