Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 39 ยท Quantum Programming Tools

Cirq, PennyLane, Braket, Q# and Other Quantum SDKs

Compare the main quantum programming frameworks (Cirq, PennyLane, Amazon Braket, Q#, CUDA-Q) and learn moments, parameter-shift gradients and how to choose.

Qiskit is not the only choice. Several other frameworks exist, each with a different focus: hardware access, machine learning, language design or GPU simulation. They all express the same circuit model, so skills transfer easily. After this lesson you will know what each tool is good for and how its code looks, so you can pick one for your own project.

None of these libraries run in the browser on this site. The library snippets are read-only. The runnable blocks are NumPy stand-ins for two ideas you will meet in them: circuits organized in moments, and gradients by the parameter-shift rule.

The landscape

SDK Maintainer Language Strength
Qiskit IBM Python Biggest community, IBM hardware, huge library and tooling
Cirq Google Quantum AI Python Precise control of circuits and device constraints, moments, noise modelling
PennyLane Xanadu Python Differentiable programming, quantum machine learning, hardware-agnostic
Amazon Braket SDK AWS Python Single API for several hardware vendors and managed simulators
Q# / Azure Quantum Microsoft Q# language A dedicated language with types and resource estimation
CUDA-Q NVIDIA Python, C++ Hybrid quantum-GPU workflows, very fast GPU simulation
pytket Quantinuum Python A strong compiler/optimizer that targets many backends
Ocean / Qrisp / others D-Wave, community Python Annealing and high-level programming abstractions

Cirq

Cirq builds circuits from gates applied to explicit qubit objects on a line or grid, and it groups simultaneous gates into moments.

Python
import cirq

q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit(
    cirq.H(q0),
    cirq.CNOT(q0, q1),
    cirq.measure(q0, q1, key="m"),
)
print(circuit)

result = cirq.Simulator().run(circuit, repetitions=1000)
print(result.histogram(key="m"))      # Counter({0: ~500, 3: ~500})

Cirq is big-endian when it converts measurements to integers (q0 is the most significant bit), the opposite of Qiskit's default. This is the textbook convention you have used throughout this course. The device model lets you write circuits that respect hardware geometry, which matters on Google's grid chips.

A moment is a set of gates that run at the same time on different qubits. The number of moments is the circuit depth. You can compute it yourself:

Python Moments and depth, a Cirq-style scheduler

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The GHZ chain is inherently sequential (depth 4), while four Hadamards fit into a single moment. Shorter depth means less decoherence, so depth is one of the quantities you optimize.

PennyLane

PennyLane treats a quantum circuit as a differentiable function. You wrap a circuit in a qnode, return an expectation value, and compute gradients that plug into NumPy, PyTorch, JAX or TensorFlow optimizers. That makes it the favorite for quantum machine learning and variational algorithms.

Python
import pennylane as qml
from pennylane import numpy as np

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev)
def circuit(theta):
    qml.RY(theta, wires=0)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(1))

theta = np.array(0.5, requires_grad=True)
print(circuit(theta))              # cos(0.5) = 0.8776
print(qml.grad(circuit)(theta))    # -sin(0.5) = -0.4794

opt = qml.GradientDescentOptimizer(stepsize=0.4)
for _ in range(30):
    theta = opt.step(circuit, theta)

On real hardware you cannot run backpropagation through the quantum device, because the state is not observable. PennyLane uses the parameter-shift rule instead: for a gate exp(-i * theta * P / 2) with Pauli P,

Text
d<O>/d(theta) = ( <O>(theta + pi/2) - <O>(theta - pi/2) ) / 2

It is an exact gradient, computed from two more circuit runs per parameter, not an approximation like finite differences.

Python The parameter-shift rule on a two-qubit circuit

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The two methods agree to six digits, but only the shift rule is practical on a device with shot noise, because it uses large, well-separated shifts.

Amazon Braket

Braket provides one SDK for several providers (superconducting, ion-trap, neutral-atom devices) plus managed simulators.

Python
from braket.circuits import Circuit
from braket.devices import LocalSimulator

circ = Circuit().h(0).cnot(0, 1)
result = LocalSimulator().run(circ, shots=1000).result()
print(result.measurement_counts)       # Counter({'00': ~500, '11': ~500})

Switching to real hardware means replacing LocalSimulator() with an AwsDevice("arn:..."), and paying per task and per shot.

Q# and Azure Quantum

Q# is a separate language, with qubit allocation scoped by use, adjoint and controlled functors generated automatically, and built-in tools for estimating how many physical qubits a fault-tolerant algorithm needs.

QSHARP
operation Bell() : (Result, Result) {
    use (a, b) = (Qubit(), Qubit());
    H(a);
    CNOT(a, b);
    let result = (M(a), M(b));
    ResetAll([a, b]);
    return result;
}

CUDA-Q

CUDA-Q ("kernels" in Python or C++) targets heterogeneous computing, running circuits on GPUs, QPUs or both, and scales state-vector simulation to dozens of qubits on a single GPU.

Python
import cudaq

@cudaq.kernel
def bell():
    q = cudaq.qvector(2)
    h(q[0])
    x.ctrl(q[0], q[1])
    mz(q)

print(cudaq.sample(bell, shots_count=1000))

How to choose

  • Learning and general use: Qiskit (the most tutorials, IBM hardware access).
  • Hardware-aware circuit design on grids: Cirq.
  • Quantum machine learning and optimization: PennyLane.
  • Choosing between vendors: Braket, or pytket for compiling to many backends.
  • Serious simulation performance: CUDA-Q.
  • Interoperability: all of them can import or export OpenQASM (see OpenQASM and running on hardware), so you are not locked in.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is a 'moment' in Cirq?

    Moments are time slices; the number of moments is the circuit depth.
  2. 2. How does the parameter-shift rule compute a gradient?

    d<O>/dtheta = (<O>(theta + pi/2) - <O>(theta - pi/2)) / 2, exact for standard rotation gates.
  3. 3. Which framework is built around differentiable quantum programming?

    PennyLane integrates with PyTorch, JAX and TensorFlow for hybrid training.
  4. 4. Which statement is true about Cirq and Qiskit bit order?

    Qiskit puts qubit 0 on the right; Cirq's measurement integers put the first qubit on the left.

Summary

  • Qiskit, Cirq, PennyLane, Braket, Q# and CUDA-Q all express the same circuit model with different strengths.
  • Cirq organizes gates into moments (depth); PennyLane makes circuits differentiable via the parameter-shift rule.
  • Bit-order conventions differ between libraries, so check before comparing results.
  • Pick a tool for hardware access, learning resources, ML, or simulation speed; OpenQASM keeps you portable.

Next: OpenQASM and Running on Real Hardware