# Introduction

I am using BQSKIT to compile an approximation of a Toffoli gate (for testing purposes) and output to a QISKIT QuantumCircuit. I want to find the expected value of this approximation to find out how good it is using exact methods. In an attempt to do so, I first use this circuit to get an Operator. I then create a state vector and use the expectation_value method to compute the expected value. I include the relevant code snippet below. The result is a complex number: (1.0000000000000004-6.814549413037705e-13j).

## The Code

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit.quantum_info import Operator

qc = bqskit_to_qiskit(out_circuit)
op = Operator( qc )

testVector = Statevector( QuantumCircuit( 3 ))
print('Exact:', testVector.expectation_value(op) )


# The Primary Question

1. What is the meaning of a complex expected value?

## The Secondary Questions

1. Am I using expectation_value correctly?
2. Have I correctly understood that it gives an exact solution via linear algebra and is not based on simulation?
• I suspect this is just numerical error in python! Feb 5 at 7:43

This is a floating point error. The way computers work with floating point numbers, very small errors can happen. You can check it by trying to see if 0.1+0.1+0.1 == 0.3 (spoilers, it's not, according to python, 0.1+0.1+0.1=0.30000000000000004)
I suggest using numpy.real_if_close before the result. This will identify any such errors (like your 0.00000000000068j off answer) and hide them.