Running on Real Quantum Hardware
Everything so far has run on cirq.Simulator(), an ideal, noise-free simulator. Google's real quantum processors exist too, but access works quite differently from IBM's more open model.
Google Quantum AI access
import cirq_google
# Real hardware access via Google Quantum AI requires an allowlisted Google Cloud
# project, this is not a self-serve signup the way IBM Quantum's free tier is.
engine = cirq_google.Engine(project_id='your-google-cloud-project-id')
processor = engine.get_processor('processor_id')
result = processor.run(circuit, repetitions=1000)
print(result.histogram(key='result'))
This needs an allowlisted Google Cloud project and real hardware access, so it's read-only here. Unlike IBM Quantum's public free tier (sign up and run within minutes), Google Quantum AI hardware access has historically required an approved research or partnership relationship, most learners will develop and run entirely on cirq.Simulator().
Cirq still models noise, without needing real hardware
Cirq lets you simulate with realistic noise, without needing hardware access at all, useful for understanding what real results would look like:
import cirq
q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit([
cirq.H(q0),
cirq.CNOT(q0, q1),
cirq.measure(q0, q1, key='result'),
])
noisy_circuit = circuit.with_noise(cirq.depolarize(p=0.02)) # 2% error rate per operation
simulator = cirq.Simulator()
result = simulator.run(noisy_circuit, repetitions=1000)
print(result.histogram(key='result')) # small numbers of 1 and 2 (01/10) will now appear
circuit.with_noise(cirq.depolarize(p=0.02)) returns a new circuit where every operation has a small chance (p=0.02, 2%) of introducing a random error, a simplified model of the real gate errors and decoherence discussed conceptually in the Qiskit course's hardware lesson. Running this noisy circuit will occasionally produce the "impossible" 01/10 outcomes, exactly what you'd expect to see on real, imperfect hardware.
NOTE
Simulating noise like this is genuinely useful even if you never get access to real hardware, it lets you reason about how robust an algorithm is to imperfection before ever submitting a job to any provider.