0
$\begingroup$

I referred to the following Qiskit's document: state_fidelity.

The inputs of state_fidelity are quantum state vectors or density matrices. For example, $|00\rangle$ or $|0\rangle \langle0|$.


Now, let me assume a circuit is described as follows. enter image description here

The above circuit with no noise provides $\frac{1}{\sqrt{2}}( |00\rangle + |11\rangle )$ .

When I would like to measure the noise of this circuit, I use state_fidelity and compare the measurements and $\frac{1}{\sqrt{2}}( |00\rangle + |11\rangle )$. Here, we have to obtain the state vector such as numpy.array([***]).

However, I received the following error: AerError: 'statevector_simulator does not support noise.' when I set backend = Aer.get_backend('statevector_simulator') to get the state vectors.

When I use qasm_simulator with noise_model (cf. How can noise on a device be simulated using measured noise parameters?), I obtained the following error: 'No statevector for experiment "None". However, I could obtain the counts by result().get_counts.


How can I obtain the state vector with noise_model? Do I have to calculate the state vector from the counts?

I append the code as below.

%matplotlib inline
# Importing standard Qiskit libraries and configuring account
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
# Loading your IBM Q account(s)
provider = IBMQ.load_account()

from qiskit.aqua import run_algorithm
from qiskit.aqua.input import LinearSystemInput
from qiskit.quantum_info import state_fidelity
from qiskit.aqua.algorithms.classical import ExactLSsolver

from qiskit import *
import numpy as np

from qiskit.providers.aer import noise
properties = device.properties()
noise_model = noise.device.basic_device_noise_model(properties)
basis_gates = noise_model.basis_gates

def test():
    q = QuantumRegister(2)
    c = ClassicalRegister(2)
    qc = QuantumCircuit(q,c) 
    qc.h( q[0] )
    qc.cx( q[0], q[1] )

    qc.measure(q,c)

    return qc
# test().draw()

def test2():
    q = QuantumRegister(2)
    c = ClassicalRegister(2)
    qc = QuantumCircuit(q,c) 
    qc.h( q[0] )
    qc.cx( q[0], q[1] )

#     qc.measure(q,c)

    return qc
# test2().draw()
backend = Aer.get_backend('qasm_simulator')
simulator = Aer.get_backend( 'qasm_simulator' )
job1 = execute( test(), backend, noise_model = noise_model, basis_gates= basis_gates, shots = 100 ).result().get_statevector()

backend = Aer.get_backend('statevector_simulator')
simulator = Aer.get_backend( 'statevector_simulator' )
job2 = execute( test2(), backend, noise_model=noise_model, shots = 100 ).result().get_statevector()

Thank you.

$\endgroup$
1
$\begingroup$

The reason the Statevector simulator does not handle noise is that Statevector is not a correct formulation, mathematically, for the application of noise; for this one has to work with a generalization of statevector called Density Matrix.

Obtaining the density matrix of a noisy state from the actual measurements is done by something called Quantum State Tomography which is part of qiskit-ignis. See here the tutorial.

There is, however, an alternative method which skips using the simulator altogether. You can use qiskit-terra's quantum_info library to directly obtain the quantum operator for the circuit, and compose it with a quantum operator for the noise. This requires a little more understanding of the underlying math, but the results are precise, as opposed to using state tomography which is intended for "real world" use, where you don't have a noise model.

$\endgroup$
  • $\begingroup$ I will just add that when theoretically looking at noise, the density matrix approach suggested here is a good one. However, experimentally there is always a state vector to which noise is applied. A density matrix looks at the ensemble average of experiments that possibly include noise. There are other simulation techniques that look at single-shot realizations of noise, but these are not implemented in Qiskit Aer. $\endgroup$ – Paul Nation Jan 28 at 10:52
  • $\begingroup$ Indeed, the "standard" qiskit simulator actually uses statevector as its inner data structure and changes it according to the noise. However, it means that each shot would result in a different statevector, and this output format is indeed not supported in qiskit (which outputs measurement distributions, and provides the statevector only in purely unitary simulation) $\endgroup$ – Gadi A Jan 28 at 11:50
  • $\begingroup$ Thank you for your comments. I would like to ask one question. Let assume the following result with noise where the number of shots is 100: |00>: 40, |01>:10, |10>:10, and |11>:40. This result approximately provides |s_noise> = 0.63|00> + 0.32|01 + 0.32|10> + 0.63|11> . The result with no noise provides |s_pure> = 0.71|00> + 0.71|11>. Here, what is the meaning of the inner product <s_noise|s_pure> ? What is the difference with that of Density Matrix? $\endgroup$ – Ashy Jan 29 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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