From 1f7aaffcf3ff14ac47442ae4568aaa224e0529d5 Mon Sep 17 00:00:00 2001
From: jwoehr <4604036+jwoehr@users.noreply.github.com>
Date: Wed, 16 Oct 2024 15:43:34 +0000
Subject: [PATCH] =?UTF-8?q?Deploying=20to=20main=20from=20@=20openqasm/ope?=
=?UTF-8?q?nqasm@5c4c69f398e28d1a3a1ee6f928921e29c4491d8b=20=F0=9F=9A=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
_sources/language/types.rst.txt | 59 +++++++++++++++++++++-----------
index.html | 4 ++-
language/types.html | 53 ++++++++++++++++------------
objects.inv | Bin 2356 -> 2401 bytes
release_notes.html | 31 ++++++++++++++---
searchindex.js | 2 +-
6 files changed, 102 insertions(+), 47 deletions(-)
diff --git a/_sources/language/types.rst.txt b/_sources/language/types.rst.txt
index 8428a35..41d43f8 100644
--- a/_sources/language/types.rst.txt
+++ b/_sources/language/types.rst.txt
@@ -67,8 +67,7 @@ actual hardware; see below). The statement ``qubit[size] name;``
declares a quantum register with ``size`` qubits.
Sizes must always be :ref:`compile-time constant OpenQASM Live SpecificationOpenQasm 3.0 Grammar
-
+
Qubits¶
declares a quantum register with
size
qubits.
Sizes must always be compile-time constant positive
integers.
-Quantum registers are static arrays of qubits
-that cannot be dynamically resized.
The label name[j]
refers to a qubit of this register, where
\(j\in \{0,1,\dots,\mathrm{size}(\mathrm{name})-1\}\) is an integer.
bit[size] name;
declares a register of
+statement bit name;
declares a single classical bit, while bit[size] name;
declares a register of
size
bits. The label name[j]
refers to a bit of this register, where \(j\in
\{0,1,\dots,\mathrm{size}(\mathrm{name})-1\}\) is an integer.
Bit registers may also be declared as creg name[size]
. This is included for backwards
@@ -204,6 +203,21 @@
The scalar type bit
logically represents a single bit of data, but no restrictions or suggestions are made for how an implementation should choose to store a variable declared as a scalar bit.
+The type bit[n]
behaves as if it is stored in memory as a contiguous bit-packed sequence; this is reflected in its casting rules to and from the other types.
+There are no defined semantics for how bit
or bit[n]
types should behave if used for a parameter or return value in an extern
call that implies an FFI call, and it is discouraged for implementations to allow this.
+Neither scalar bit
s nor bit[n]
registers can be the base type of an array
.
The indexing operation on a bit[n]
with an integer value returns a value of type bit
, and a value of type bit
can be assigned to a single integer offset into a bit[n]
type.
Values being used in an expression (r-values, in C parlance) with types bool
and (scalar) bit
are interchangeable; whenever a value can be implicitly cast to type bool
, it can also implicitly be cast to type bit
and vice versa.
+For example, it is legal to initialize and set bit
values using the integer literals 0
, 1
, and the Boolean literals false
and true
.
+Similarly, it is legal to use a bit
-valued expression as the condition of an if
statement.
Note
+Despite having the same bit length, the types bit
and bit[1]
are distinct.
+bit
is a scalar that is interchangeable with bool
, while bit[1]
is a register type of length one.
+The literals false
, true
, 0
and 1
can be assigned to a value of type bit
, while the literals "0"
and "1"
are the corresponding literals for bit[1]
.
The distinction is important in the type-checking of broadcast expressions, and in the implied semantics of the type.
+There is a Boolean type bool name;
that takes values true
or false
. Qubit measurement results
-can be converted from a classical bit
type to a Boolean using bool(c)
, where 1 will
-be true and 0 will be false.
There is a Boolean type bool name;
that takes values true
or false
.
+The Boolean type is byte aligned, and can be the base type of an array
.
When used in expressions, values of type bool
can always be implicitly cast to the equivalent scalar bit
, and vice versa.
+The difference between bool
and bit
is primarily about the expectations of storage requirements; bit
is used when the storage is expected to be bit-packed, such as in the special register type bit[n]
.
+bool
is a byte-aligned single-bit integer type.
bit my_bit = 0;
bool my_bool;
// Assign a cast bit to a boolean
-my_bool = bool(my_bit);
+my_bool = my_bit;
The first argument to the array
declaration is the base type
-of the array. The supported classical types include various sizes of bit
,
-int
, uint
, float
, complex
, and angle
, as well as
-bool
and duration
. Note that stretch
is not a valid array
-base type.
The first argument to the array
declaration is the base type of the array.
+The supported classical types include any sizes of int
, uint
, float
, complex
, and angle
, as well as bool
and duration
.
+Note that bit
, bit[n]
and stretch
are not valid array base types, nor are any quantum types.
Arrays cannot be resized or reshaped. Arrays are statically typed, and cannot implicitly convert to or from any other type.
The size of an array is constant and immutable, and is recorded once, at @@ -790,11 +804,7 @@
myArr[1, 2, 3]
), with the outer
dimension specified first.
-For interoperability, the standard
-ways of declaring quantum registers and bit registers are equivalent to the
-array syntax version (i.e. qubit[5] q1;
is the same as
-array[qubit, 5] q1;
).
-Assignment to elements of arrays, as in the examples above, acts as expected,
+
Assignment to elements of arrays, as in the examples above, acts as expected, with the left-hand side of the assignment operating as a reference, thereby updating the values inside the original array. For multi-dimensional arrays, the shape and type of the assigned value must match that of the reference.
@@ -1119,9 +1129,9 @@bool
values cast from false
to 0.0
and from true
to 1.0
or
-an equivalent representation. bool
values can only be cast to bit[1]
-(a single bit), so explicit index syntax must be given if the target bit
-has more than 1 bit of precision.
bool
values are interchangeable with scalar bit
values.
+Because of this, a bool
can be assigned to a single index of a bit[]
register type, or an explicit cast can be used to convert a bool
into a bit[n]
value for any n
, where all bits are 0
except for the low bit, which has the same value as the Boolean.
uint[n]
is expected to preserve the bit
ordering, specifically it should be the case that x == int[n](uint[n](x))
and vice versa. Casting to bit[m]
is only allowed when m==n
. If the target
-bit
has more or less precision, then explicit slicing syntax must be given.
+bit[]
has more or less precision, then explicit slicing syntax must be given.
As noted, the conversion is done assuming a little-endian 2’s complement
representation.
The scalar bit
is implicitly interchangeable with bool
.
I%Cs69TK%_`w<-N+YVx~VN
zd9klWMO9Z)(=kS7PUigl`PZ+)qC2EP`gN(!oo5100$A8+M*(Qs(#jQowUI22geV9j
zd*2`U1Q19rE!;zh9C@fLrJ7z$Da95p@_+yOdw-|u9FhC?uYVY+VWh2xF~A6~DX&}f
z3g{EA!_wtIAVh{n$&D5N9?O!HvTUc^20f3zuJx{zc_GJ=z4~Bo78;4+s0Lkb;TA@#
zxG0P98kWTarM%QT=^r}dgefGFE3((J&SRGHxk<{093gy}Zkv*@13UVhT(@9kq}-bN
zhJQ?Yvo0<|mh6flO+3{%F+U*<5b^2HjoA6xvsj8k$_wRlVr6Z8q&9jN!F`hZ!UWoS
zO_9iy$y(R}{=*Pr1rl|b^Gwt{m0be_*U~-9C85G{tfgq*?2C0Pj1nmZzyhD}o&i4i
zw$XKNyEx~HnrkLmD&0=Xnkb^eU@W0b5`WjMr)z96gAcon!iobfV427qv8?keB*(`t
zM~b)JeArwyFcGG@O(mVmR{SaE&~{i%z1>>}-Vpr|0DrQeGW)?3?Z;3t4?>mcvh8}H
ze-D9RjnN20)rD`Z+nz~e6Np;1PR`}jSmhav$I-&^E#iW-gcmR3o7EGft{RU*2!Aof
zVY=qmKcD>ifTyS^ ;iuGn8b>c5h}j1TW5z!)zPtn
zpC6q3M(WCh#&raupAIk={X08k<)rq&SN@b9*{G~;W$JJy=zn|}$Jk*t9#QM+bhyoT
z#Wx*ww1e6oyC?Db*?~PTyl_YQUNRirCqd$=-XnPJq{JDZ93N`za4)64K5AaW3O3Wt
zw3U7);9ue~-aEQO`N-MZU(Ke`rarCl%Q(v8D4Y6xHH~-c^A^7xebPFt=}G;e+W9Ll
zL=lQr&nlfy^nbTzpL7#J@hj9W_NCD2n$13Z|BCzOj3)CUs_<{T3iByV2Fl-6A0?gi
z7pHyX!h3vsvBzz>K6KGY91Sd;t$=++t?}XZY<0RiNlrgGgo~0_UNV>)hY~-OkaDs;
zOHPxZe1P@Ng|5<;Zn-zNW3+I|1TaZ}`3!)c)6=`xt$%UcT}$Eo@#}vr4Wy(;qEqze
z@#WnHv<)`RJWl>U3nEmQ The types The Some minor mathematical errors in the descriptions of the explicit gate
actions in 9eHjgc
zG!#|iIeLcf(Release Notes¶
-spec/v3.1.0-11¶
+spec/v3.1.0-12¶
+New Features¶
+
+
+bool
and (scalar) bit
are now explicitly described as being completely
+interchangeable in expression (r-value) positions, and that bit
and bit[1]
are distinct
+types. The difference between the types bool
and bit
is only in their intended storage
+mechanisms; bit
is the scalar of the register-type bit[n]
, which is explicitly a
+bit-packed type, so cannot be used as the base type of an array
, while bool
is a
+byte-aligned single-bit integer-like type. bit[1]
is a register (sequence) type that
+happens to be of length one.Upgrade Notes¶
+
+
+qubit
type is no longer a valid base type for an array
, and it is no longer stated
+that the register type qubit[n]
is equivalent to an array
; there is no need for these
+semantics, and they clashed with the classical considerations and alignment concerns of arrays
+in general.Bug Fixes¶
+Bug Fixes¶
sdg
, rx
, ry
, rz
, crx
and
@@ -70,7 +91,9 @@ Navigation
-
+