1

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?

Ashok Kumar Jayaraman
  • 2,887
  • 2
  • 32
  • 40
  • Check that you installed cirq correctly (https://quantumai.google/cirq/start/install) and make sure your python files aren't named 'cirq.py' or other module names from the cirq library. Here's the output I got from your code: Circuit: (0, 0): ───X^0.5───M('m')─── – belwood Jan 16 '23 at 08:39

1 Answers1

0

@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. :)