AttributeError: module 'cirq' has no attribute 'GridQubit'

731 views Asked by At

I tried the following code in nvidia-dgx2 machine.

import cirq

# Pick a qubit.
qubit = cirq.GridQubit(0, 0)

# Create a circuit
circuit = cirq.Circuit(
    cirq.X(qubit)**0.5,  # Square root of NOT.
    cirq.measure(qubit, key='m')  # Measurement.
)
print("Circuit:")
print(circuit)

# Simulate the circuit several times.
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=20)
print("Results:")
print(result)

But, I get the attribute error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_36197/3759634386.py in <module>
      2 
      3 # Pick a qubit.
----> 4 qubit = cirq.GridQubit(0, 0)
      5 
      6 # Create a circuit

AttributeError: module 'cirq' has no attribute 'GridQubit'

Any solution to this issue?

1

There are 1 answers

0
Entangle Software On

@belwood is correct. I have renamed the file as cirq.py and that's why it started to search for dependencies in this file only and hence the error. Just renamed the file to any other file name and it should work. :)