I'm trying to run state tomography on a custom pulse gate (currently just a CR(pi/4) pulse) and any attempt to run it on an IBM backend gives a maximum allowed dimension exceeded error. The code runs fine for any standard gates on the backend.
All the potentially relevant code is:
from qiskit_experiments.library import StateTomography
from qiskit import pulse
service = QiskitRuntimeService()
backend = service.get_backend(name='ibm_kyoto')
#Extracts the CR(pi/4) pulse
from qiskit.pulse import Play
backend_defaults = backend.defaults()
inst_sched_map = backend_defaults.instruction_schedule_map
cr_pulse = inst_sched_map.get('ecr', (1,0)).filter(channels = [ControlChannel(1)], instruction_types=[Play]).instructions[0][1].pulse
with pulse.build(backend, name="Default CR") as cr_sched_default:
pulse.play(cr_pulse, ControlChannel(1))
from qiskit.circuit import Gate
from qiskit.pulse import builder
from qiskit.transpiler import InstructionProperties
# Makes the circuit, turns it into a schedule
circ = QuantumCircuit(4)
custom_gate = Gate('cr', num_qubits=2, params=[])
circ.add_calibration('cr', [0,1], cr_sched_default)
circ.append(custom_gate, [0,1])
backend.target.add_instruction(
custom_gate,
{(0,1): InstructionProperties(calibration=cr_sched_default)},
)
circ = transpile(circ, backend)
#runs the state tomography and returns the results
from qiskit_ibm_provider import IBMProvider
provider = IBMProvider()
backend = provider.get_backend(name='ibm_kyoto')
with backend.open_session() as session:
qstexp = StateTomography(circ, measurement_indices=[0,1])
qstdata = qstexp.run(backend).block_for_results()
for result in qstdata.analysis_results():
print(result)
state_result = qstdata.analysis_results("state")
print(state_result.value)
Much of the code comes from the qiskit textbook: https://github.com/Qiskit/textbook/blob/main/notebooks/quantum-hardware-pulses/hamiltonian-tomography.ipynb
The error is:
ValueError Traceback (most recent call last)
Cell In[97], line 10
6 backend = provider.get_backend(name='ibm_kyoto')
9 with backend.open_session() as session:
---> 10 qstexp = StateTomography(circ, measurement_indices=[0,1])
11 qstdata = qstexp.run(backend).block_for_results()
13 for result in qstdata.analysis_results():
File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\qiskit_experiments\warnings.py:169, in deprecate_arguments.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
160 if kwargs:
161 _rename_kwargs(
162 args[0].__class__.__name__ + "." + func.__name__,
163 kwargs,
(...)
167 stacklevel,
168 )
--> 169 return func(*args, **kwargs)
File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\qiskit_experiments\library\tomography\qst_experiment.py:122, in StateTomography.__init__(self, circuit, backend, physical_qubits, measurement_basis, measurement_indices, basis_indices, conditional_circuit_clbits, analysis, target)
120 if isinstance(self.analysis, TomographyAnalysis):
121 if target == "default":
--> 122 target = self._target_quantum_state()
123 self.analysis.set_options(target=target)
File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\qiskit_experiments\library\tomography\qst_experiment.py:138, in StateTomography._target_quantum_state(self)
136 state = DensityMatrix(circuit)
137 else:
--> 138 state = Statevector(circuit)
139 except QiskitError:
140 # Circuit couldn't be simulated
141 return None
File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\qiskit\quantum_info\states\statevector.py:91, in Statevector.__init__(self, data, dims)
89 self._data = np.ravel(data.data)
90 elif isinstance(data, (QuantumCircuit, Instruction)):
---> 91 self._data = Statevector.from_instruction(data).data
92 else:
93 raise QiskitError("Invalid input data format for Statevector")
File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\qiskit\quantum_info\states\statevector.py:765, in Statevector.from_instruction(cls, instruction)
763 instruction = instruction.to_instruction()
764 # Initialize an the statevector in the all |0> state
--> 765 init = np.zeros(2**instruction.num_qubits, dtype=complex)
766 init[0] = 1.0
767 vec = Statevector(init, dims=instruction.num_qubits * (2,))
ValueError: Maximum allowed dimension exceeded
Does anyone know what am I missing?