quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.24k stars 1.01k forks source link

Error in using Class TwoQubitGate #6557

Closed kvvedavyasa closed 5 months ago

kvvedavyasa commented 5 months ago

I want to create a Class MyGate(cirq.TwoQubitGate). I have written the code in the correct syntax provided using colab AI. But, I am getting an attribute error at last like "AttributeError: module 'cirq' has no attribute 'TwoQubitGate' ''

Following is the code:

* import cirq

Define a custom two-qubit gate

class MyGate(cirq.TwoQubitGate): def init(self, θ, φ): super().init() self.θ = θ self.φ = φ

def _num_qubits_(self):
    return 2

Create an instance of the gate

gate = MyGate(np.pi/4, np.pi/8)

Create a quantum circuit

qubits = cirq.LineQubit.range(2) circuit = cirq.Circuit()

Apply the gate to the circuit

circuit.append(gate(qubits[0], qubits[1]))

Print the circuit

print(circuit) * Why I am getting the Attribute Error : module 'cirq' has no attribute 'TwoQubitGate' . I have also updated cirq using 'pip install --upgrade cirq' where it is showing Requirements already satisfied.

Cirq version:1.3.0

Error image

pavoljuhas commented 5 months ago

TwoQubitGate was removed in #4601. Please use cirq.Gate instead.