Skip to main content
Introducing The Quantum Infrastructure Cloud Learn more

DevelopersHiQ / Language

HiQ Script

Constants, inclusive for loops, repeat until, select, initialised declarations and parallel tasks that are checked so every interleaving gives the same result.

  • .qcos2
  • qcos-l2/0
  • Imperative; end and next close blocks
  • Lowers to HiQ Assembly

Script adds constants, constant expressions in indices and angles, inclusive for, repeat ... until, initialised declarations and parallel. Blocks close with words, not braces. Comments start with #.

Declarations

FormMeaning
const N = 3A compile-time constant, usable in bounds, indices and angles
qubit a, b, qubit q[N]Qubits
bit m, bit m[N], bool mBits
uint8 c = 2, int32 zIntegers, with an optional initial value
sub f(q; k: uint8) ... endA routine

Qubits and arrays take no initial value (lang.init).

Statements

FormMeaning
h a, rz(pi / N) q[i], cx q[i], q[i + 1]A gate
measure a into mMeasure
reset aReset
alloc tAllocate
free t or free t resetRelease. clean is the default
let x = y + 1Assignment
for i = 0 to N - 1 step 1 ... nextA loop known at compile time, stop included. step is optional and may be negative
while m limit 10 ... endA real-time loop
repeat ... until m limit 3Run the body, then repeat until the condition holds, at most the limit in total
if m then ... elseif n then ... else ... endA branch
select x / case 1, 2: ... / default: ... / endA switch
compute ... do ... endThe form of Assembly's within
call f(a; 1)A call
parallel / task one ... end / endTasks, see below

Script expressions also take and, or, not, mod and <> for not-equal. Division is allowed only between constants, in constant expressions. A division of whole numbers that leaves no remainder is a whole number, so const HALF = N / 2 can bound a loop; 3 / 2 is 1.5 and can only be part of an angle.

parallel

Tasks are checked statically. They may not share a qubit (task.shares_qubit), and a variable one task writes may not be touched by another (task.shares_variable). Every interleaving then gives the same result, so tasks lower in sequence, and disjoint operations overlap in the reported depth. There is no concurrent execution on control hardware.

Idioms

HiQ Scriptqcos-l2/0
program ghzconst N = 3qubit q[N]bit m[N]h q[0]for i = 0 to N - 2  cx q[i], q[i + 1]nextfor i = 0 to N - 1  measure q[i] into m[i]next
HiQ Scriptqcos-l2/0
program feedbackqubit a, bbit m, nuint8 c = 1h ameasure a into mif m and c == 1 then  x belseif m then  z belse  h bendmeasure b into n
HiQ Scriptqcos-l2/0
program until_onequbit abit mrepeat  h a  measure a into m  reset auntil m limit 3
HiQ Scriptqcos-l2/0
program choosequbit abit muint8 c = 2sub flip(q; k: uint8)  x qendselect c  case 1, 2:    call flip(a; 1)  default:    h aendmeasure a into m
HiQ Scriptqcos-l2/0
program side_by_sidequbit a, bbit muint8 c = 0parallel  task one    x a  end  task two    h b    let c = 1  endendmeasure a into m

Refused, with the code

Refused by the checkertask.shares_qubit
program pqubit a, bparallel  task x    h a  end  task y    cx a, b  endend
Refused by the checkerloop.unbounded
program pbit mwhile mend

Examples in this layer