← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe

Google Quantum AI

Cirq starter package

SoftwareQuantum SDKLicence: Apache-2.0Version: 1.7.09.1 KB

Official source: quantumlib/Cirq

Download ZIP (free)

Cirq, Google Quantum AI's Python framework for NISQ circuits: an English guide and a tested three-qubit GHZ state example.

What is Cirq?

Cirq is the Python library Google Quantum AI developed for noisy intermediate-scale quantum (NISQ) computers. It stands out for modelling the placement of qubits on hardware and the timing of gates (moments) explicitly.

When to use it

The example in this package

ghz_durumu.py puts three qubits into a GHZ state and measures them 1000 times. The three qubits together give either 000 or 111; mixed results never appear.

Next steps

  1. Use cirq.DensityMatrixSimulator and circuit.with_noise(cirq.depolarize(0.01)) to see how noise spoils the result.
  2. Try the fast simulator qsimcirq for larger circuits.

Installation and running

pip install cirq-core
python ghz_durumu.py

Tested with: cirq-core 1.7.0, Python 3.12.

Official source

Links

Package contents

Licence

The example code and the guide in this package were written by the Quantum Store editors and are MIT licensed. The project it uses is subject to its own licence (Apache-2.0).


Quantum Store — https://hakanerdogan.com/en

Example code

The example shipped in the package, run and checked. Comments and printed messages are in Turkish; the code is the same in any language. Everything is in the ZIP.

ghz_durumu.py

"""Cirq ile 3 kübitlik GHZ durumu hazırla ve simüle et.

Çalıştırma:
    pip install cirq-core
    python ghz_durumu.py
"""

import cirq

q = cirq.LineQubit.range(3)
circuit = cirq.Circuit(
    cirq.H(q[0]),
    cirq.CNOT(q[0], q[1]),
    cirq.CNOT(q[1], q[2]),
    cirq.measure(*q, key="m"),
)
print(circuit)

result = cirq.Simulator(seed=7).run(circuit, repetitions=1000)
hist = result.histogram(key="m")
print("Sonuçlar (tamsayı olarak):", dict(sorted(hist.items())))

# GHZ durumunda üç kübit birlikte ya 000 (0) ya da 111 (7) ölçülür.
assert set(hist) <= {0, 7}, hist
print("Tamam: yalnızca 000 ve 111 ölçüldü.")

Related concepts

← All packages

Share: X · LinkedIn