Given a circuit, if one wishes to add a gate, it is done through a line like the one below
Here, we have added a control-X gate on the 0 and 1 qubits. This is probably a Python question but how can one do this given the string
'cx' and integers
1 i.e. without manually typing them?
I tried using https://stackoverflow.com/questions/3061/calling-a-function-of-a-module-by-using-its-name-a-string but getattr did not work for me.
from qiskit import QuantumCircuit circ = QuantumCircuit(2) circ.draw() a = ('cx', 0, 1) circ = getattr(circ, a)(a, a) circ.draw()