2
$\begingroup$

In a real quantum computer, can the save_statevector function be used to obtain the state vector of a circuit? I attempted to run the following code on a real quantum computer but encountered a job rejection. I found that save_statevector performs measurements on all qubits directly when executed on real quantum computer, yet I haven't found in the official documentation a way to specify which particular qubits to measure using this function. How can I configure the save_statevector function to measure only the qubits I need? Alternatively, is it the case that this function cannot be utilized on a real quantum computer? Or is there someting wrong with my code?

Here is my code:

from qiskit import QuantumCircuit
from qiskit import transpile
from qiskit_ibm_runtime import QiskitRuntimeService

token='*********************************'
service = QiskitRuntimeService(channel="ibm_quantum", token=token)
backend = service.least_busy(simulator=False, operational=True)

n_qubits = 3
# backend = GenericBackendV2(n_qubits)

# Create a simple circuit
circuit = QuantumCircuit(n_qubits)
circuit.h(0)
circuit.cx(0, 1)
circuit.cx(0, 2)
transpiled_circuit = transpile(circuit, backend)
transpiled_circuit.draw()
transpiled_circuit.save_statevector()
# Run the transpiled circuit using the simulated fake backend
job = backend.run(transpiled_circuit)
result = job.result()
outputstate = result.get_statevector(transpiled_circuit, decimals=100)
print(outputstate)

enter image description here

enter image description here

$\endgroup$
1
  • $\begingroup$ Real/fake backends don't support save_statevector. $\endgroup$
    – Yunzhe
    Commented Apr 26 at 9:30

2 Answers 2

4
$\begingroup$

Alternatively, is it the case that this function cannot be utilized on a real quantum computer?

Exactly! When you perform a computation on a simulator, it has to keep track of the statevector all along, which allows it to give it to you at the end.

But now, how does a quantum computer work? Well, it starts from the $|0\rangle^{\otimes n}$ state, applies the circuit you've defined and then measures this quantum state. Note that the measure is mandatory: this is the only way to get classical information out of a quantum state.

So, contrarily to a simulator, the quantum computer doesn't store the statevector. In fact, that's the whole point of using quantum computers: simulating statevectors is computationally expensive, but getting information out of it using a quantum circuit is way cheaper for a larger number of qubits.

$\endgroup$
3
  • $\begingroup$ Thanks a lot! It's very helpful! But i still wonder: if i can only rely on measurement to get classical information out of a quantum state, how can i differentiate between the positive and negative signs, or distinguish between real and imaginary components of quantum states, such as differentiating between |0⟩ and -|0⟩, |1⟩, and |i⟩, when their ultimate measurement probabilities appear identical?For example, like HHL algorithm, how can i differentiate between the positive and negative signs of each resulting vector's element? And how can i handle situations involving complex numbers? $\endgroup$
    – MrEightL
    Commented Apr 28 at 19:43
  • $\begingroup$ @MrEightL What you want to do is called state tomography. If you want to get all possible information on a quantum state $|\psi\rangle$ then you have to measure in $2^n+1$ different bases. However you might learn $\mathrm{e}^{\mathrm{i}\theta}|\psi\rangle$ by doing so, and there's nothing you can do about it. $\theta$ is called a global phase and it has physically no sense: there's no way to evaluate it. In particular, you can't tell apart $|0\rangle$ from $-|0\rangle$, since they just differ by a global phase of $\pi$. $\endgroup$
    – Tristan Nemoz
    Commented Apr 29 at 5:59
  • $\begingroup$ @MrEightL Complex numbers can be dealt with with tomography. Once again it will be up to a global phase, but apart from that it works just fine $\endgroup$
    – Tristan Nemoz
    Commented Apr 29 at 6:01
0
$\begingroup$

To add to the above answer by Tristan, if you want to simulate statevectors then you can use AerSimulator(method='statevector', noise_model=noise_model). In this function by using the noise_model option you can specify custom noise models for simulator, to automatically generate a basic device noise model for an IBMQ or a fake backend. You can read more about it here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.