Skip to content

Commit

Permalink
Add partial release note
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelishman committed Nov 29, 2023
1 parent 39d7e32 commit cf88e59
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions releasenotes/notes/classical-store-e64ee1286219a862.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
features:
- |
A :class:`.QuantumCircuit` can now contain typed classical variables::
from qiskit.circuit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit.circuit.classical import expr, types
qr = QuantumRegister(2, "q")
cr = ClassicalRegister(2, "c")
qc = QuantumCircuit(qr, cr)
# Add two input variables to the circuit with different types.
a = qc.add_input("a", types.Bool())
mask = qc.add_input("mask", types.Uint(2))
# Test whether the input variable was true at runtime.
with qc.if_test(a) as else_:
qc.x(0)
with else_:
qc.h(0)
qc.cx(0, 1)
qc.measure(qr, cr)
# Add a typed variable manually, initialized to the same value as the classical register.
b = qc.add_var("b", expr.lift(cr))
qc.reset([0, 1])
qc.h(0)
qc.cx(0, 1)
qc.measure(qr, cr)
# Store some calculated value into the `b` variable.
qc.store(b, expr.bit_and(b, cr))
# Test whether we had equality, up to a mask.
with qc.if_test(expr.equal(expr.bit_and(b, mask), mask)):
qc.x(0)
These variables can be specified either as *inputs* to the circuit, or as scoped variables.
The circuit object does not yet have support for representing typed classical-variable *outputs*,
but this will be added later when hardware and the result interfaces are in more of a position
to support it. Circuits that represent a block of an inner scope may also capture variables
from outer scopes.
A variable is a :class:`.Var` node, which can now contain an arbitrary type, and represents a
unique memory location within its live range when added to a circuit. These can be constructed
in a circuit using :meth:`.QuantumCircuit.add_var` and :meth:`~.QuantumCircuit.add_input`, or
at a lower level using :meth:`.Var.new`.
Variables can be manually stored to, using the :class:`.Store` instruction and its corresponding
circuit method :meth:`.QuantumCircuit.store`. This includes writing to :class:`.Clbit` and
:class:`.ClassicalRegister` instances wrapped in :class:`.Var` nodes.
Variables can be used wherever classical expressions (see :mod:`qiskit.circuit.classical.expr`)
are valid. Currently this is the target expressions of control-flow operations, though we plan
to expand this to gate parameters in the future, as the type and expression system are expanded.

0 comments on commit cf88e59

Please sign in to comment.