Bengali
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

qiskit.circuit.QuantumCircuit.prepare_state

QuantumCircuit.prepare_state(state, qubits=None, label=None)

Prepare qubits in a specific state.

This class implements a state preparing unitary. Unlike qiskit.extensions.Initialize it does not reset the qubits first.

প্যারামিটার
  • state (str or list or int or Statevector) --

    • Statevector: Statevector to initialize to.

    • str: labels of basis states of the Pauli eigenstates Z, X, Y. See Statevector.from_label(). Notice the order of the labels is reversed with respect to the qubit index to be applied to. Example label '01' initializes the qubit zero to \(|1\rangle\) and the qubit one to \(|0\rangle\).

    • list: vector of complex amplitudes to initialize to.

    • int: an integer that is used as a bitmap indicating which qubits to initialize to \(|1\rangle\). Example: setting params to 5 would initialize qubit 0 and qubit 2 to \(|1\rangle\) and qubit 1 to \(|0\rangle\).

  • qubits (QuantumRegister or Qubit or int) --

    • QuantumRegister: A list of qubits to be initialized [Default: None].

    • Qubit: Single qubit to be initialized [Default: None].

    • int: Index of qubit to be initialized [Default: None].

    • list: Indexes of qubits to be initialized [Default: None].

  • label (str) -- An optional label for the gate

রিটার্নস

a handle to the instruction that was just initialized

রিটার্ন টাইপ

qiskit.circuit.Instruction

Examples

Prepare a qubit in the state \((|0\rangle - |1\rangle) / \sqrt{2}\).

import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(1)
circuit.prepare_state([1/np.sqrt(2), -1/np.sqrt(2)], 0)
circuit.draw()

output:

     ┌─────────────────────────────────────┐
q_0: ┤ State Preparation(0.70711,-0.70711) ├
     └─────────────────────────────────────┘

Prepare from a string two qubits in the state \(|10\rangle\). The order of the labels is reversed with respect to qubit index. More information about labels for basis states are in Statevector.from_label().

import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.prepare_state('01', circuit.qubits)
circuit.draw()

output:

     ┌─────────────────────────┐
q_0: ┤0                        ├
     │  State Preparation(0,1) │
q_1: ┤1                        ├
     └─────────────────────────┘

Initialize two qubits from an array of complex amplitudes .. code-block:

import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.prepare_state([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
circuit.draw()

output:

     ┌───────────────────────────────────────────┐
q_0: ┤0                                          ├
     │  State Preparation(0,0.70711,-0.70711j,0) │
q_1: ┤1                                          ├
     └───────────────────────────────────────────┘