Friday, May 10, 2024

Statevector

 One can see the state of each qubit in a circuit, but the statdevector refers to the

circuit as a whole:

                                                                         



The bar turns red when the phase is negative.


*     *     *

You

Quantum computing; what is the statevector of a circuit

Copilot

The statevector in quantum computing fully describes the quantum system by encoding the probability amplitude and phase corresponding to each basis state configuration the qubits can assume. It’s a complex vector that represents the quantum state of the system.


When you apply gates to a quantum circuit, the statevector evolves. You can extract and plot snapshots of the statevector after every applied gate operation to understand how the qubit state changes mathematically1. Let’s dive into some details:


Statevector Representation:

The statevector is a vector in a complex vector space. For an n-qubit system, it lives in a 2^n-dimensional Hilbert space.

Each entry in the statevector corresponds to a specific basis state. For example, if you have a single qubit, the statevector has two complex numbers: one for the |0⟩ state and another for the |1⟩ state.

The probability of measuring a particular outcome is the squared magnitude of the corresponding entry in the statevector.

Saving Statevectors in Qiskit:

In Qiskit (a popular quantum computing library), you can save the statevector at different points in your circuit for analysis.

To save the statevector, use the save_statevector() method in your quantum circuit.

However, you cannot save the statevector more than once in the same circuit directly. If you try, you’ll encounter an error.

Instead, you can create separate copies of your circuit at each step where you want to save the statevector. Then, save the statevector for each copy2.

Here’s an example of how you can save intermediate statevectors in Qiskit:


Python

from qiskit import QuantumCircuit, Aer, transpile

# Create a quantum circuit

q1 = QuantumCircuit(2)

q1.h(0)  # Apply Hadamard gate

q1.cx(0, 1)  # Apply CNOT gate

# Save statevector after Hadamard and CNOT

q1.save_statevector()  # Save initial state

backend = Aer.get_backend('aer_simulator')

q1 = transpile(q1, backend)

result = backend.run(q1).result()

statevector = result.get_statevector()

print(statevector)


Remember that the statevector provides a complete description of the quantum state, allowing you to analyze the system’s behavior at different points in your circuit. 😊🔬21.

                                                      *     *     *

Yet another try for Qiskit 1. Think I will just move on to the next tutorial...                                    

No comments: