I have been trying to make a gate in qiskit in terms of the basic gates, but I keep on getting an error when I apply it to a circuit.
This is my gate:
class LGate(Gate):
def __init__(self, label=None):
super().__init__('l', 1, [], label=label)
def _define(self):
from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.circuit.library import U3Gate
q = QuantumRegister(1, 'q')
qc = QuantumCircuit(q, name=self.name)
rules = [
(U3Gate(pi, 0, pi), [q[0]], [])
]
qc._data = rules
self.definition = qc
Of course this is just an X gate, but I was just trying a basic example.
Running the program:
circ = QuantumCircuit(2)
circ.l(0)
print(circ)
Error:
AttributeError: 'QuantumCircuit' object has no attribute 'l'