1
$\begingroup$

I am trying to do some state tomography to generate GHZ states and calculate fidelity. For running the code, I want to execute my code with the qubits with the lowest readout error using initial layout in the transpilation process. However, I arrive at this error and I can not specify the qubits .

Traceback (most recent call last):
  Cell In[28], line 2
    best_qc = transpile(st, backend, initial_layout=[90,94,95])
  File /opt/conda/lib/python3.10/site-packages/qiskit/compiler/transpiler.py:338 in transpile
    output_name = _parse_output_name(output_name, circuits)
  File /opt/conda/lib/python3.10/site-packages/qiskit/compiler/transpiler.py:593 in _parse_output_name
    return [circuit.name for circuit in circuits]
  File /opt/conda/lib/python3.10/site-packages/qiskit/compiler/transpiler.py:593 in <listcomp>
    return [circuit.name for circuit in circuits]
AttributeError: 'StateTomography' object has no attribute 'name' 




from qiskit import *
from qiskit.visualization import array_to_latex
from qiskit_experiments.library import StateTomography
q1 = QuantumRegister(1)
q2 = QuantumRegister(1)
q3 = QuantumRegister(1)
c = ClassicalRegister(3)
qc = QuantumCircuit(q1, q2, q3, c)
qc.h(q1)
qc.cx(q1, q2)
qc.ccx(q1, q2, q3)
st = StateTomography(qc)
best_qc = transpile(st, backend, initial_layout=[90,94,95])
stdata = st.run(backend).block_for_results()
state_result = stdata.analysis_results("state")
array_to_latex(state_result.value)
fid_result = stdata.analysis_results("state_fidelity")
print(f"state Fidelity = {fid_result.value}") 




                                                                                                                                                                                                                                                                                                                                                                                              
$\endgroup$

1 Answer 1

0
$\begingroup$

You can't use transpile with an instance of StateTomography because it is not a circuit. The proper way to achieve your goal is to use StateTomography parameter physical_qubits.

So, you should replace these two lines:

st = StateTomography(qc)
best_qc = transpile(st, backend, initial_layout=[90,94,95])

with

st = StateTomography(qc, physical_qubits=[90,94,95])

Internally, StateTomography.run() method will transpile the experiment circuits and use physical_qubits as initial_layout.


Note, you can use the following code snippet if you want to check that the specified qubits are actually used:

from qiskit.visualization import plot_circuit_layout

plot_circuit_layout(st._transpiled_circuits()[0], backend=backend, view='physical')
$\endgroup$
1
  • $\begingroup$ Thank you so much. That was really eye opener and helpful. $\endgroup$
    – physicino
    Mar 19 at 8:56

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.