Concatenation Operator
The concatenation operator is a new Qmod language feature that helps us operate on a quantum object created ad-hoc from parts of other objects. For example, the following Qmod model calls hadamard_transform
with the concatenation [x1[3], x2[1:3], x1[0]]
.
@qfunc
def main():
x1 = QArray(length=4)
allocate(x1)
x2 = QArray(length=4)
allocate(x2)
hadamard_transform([x1[3], x2[1:3], x1[0]])
A concatenation specifies a sequence of (possibly partial) quantum variables. In Python, this is done with a Python list (the Native Qmod syntax is {...}
). In the model above, function hadamard_transform
is passed a concatenation of three variable parts: x1[3]
, x2[1:3]
, and x1[0]
. The qubits belonging to these parts are packed into a new array variable right before they are sent to hadamrd_transform
. After compiling the model, we can watch the resulting circuit on the Classiq IDE. We see that hadamard_transform
is applied to the qubits specified in the concatenation, namely, the first and last qubits of x1
and the middle two qubits of x2
.

The concatenation operator is not only a convenient feature, but it also helps the programmer to avoid quantum programming bugs. For instance, consider the following model:
@qfunc
def my_control_h(ctrl: QBit, target: QArray):
control(ctrl, lambda: hadamard_transform(target))
@qfunc
def main():
x1 = QArray(length=4)
allocate(x1)
x2 = QArray(length=4)
allocate(x2)
my_control_h(x2[2], [x1[3], x2[1:3], x1[0]])
Function my_control_h
receives a qubit ctrl
and an array target
and applies a controlled Hadamard gate to ctrl
and each qubit of target
. The main
function calls my_control_h
with x2[2]
as the control and a concatenation [x1[3], x2[1:3], x1[0]]
as the target. When we compile the program, we get the following error:
Quantum cloning violation: Arguments 'x2[2]' and 'x2[1:3]' overlap
(This error points to the my_control_h
call.)
Using the same qubit in two different arguments of a quantum gate is not feasible in quantum computation. In the my_control_h
call, the qubit of the first argument x2[2]
also appears in the concatenation, as the second qubit of x2[1:3]
. This has to be a mistake! The Qmod compiler detects this violation and reports an error.
Currently, concatenations are only supported in function call arguments.
The concatenation operator is a new Qmod language feature that helps us operate on a quantum object created ad-hoc from parts of other objects. For example, the following Qmod model calls hadamard_transform
with the concatenation [x1[3], x2[1:3], x1[0]]
.
@qfunc
def main():
x1 = QArray(length=4)
allocate(x1)
x2 = QArray(length=4)
allocate(x2)
hadamard_transform([x1[3], x2[1:3], x1[0]])
A concatenation specifies a sequence of (possibly partial) quantum variables. In Python, this is done with a Python list (the Native Qmod syntax is {...}
). In the model above, function hadamard_transform
is passed a concatenation of three variable parts: x1[3]
, x2[1:3]
, and x1[0]
. The qubits belonging to these parts are packed into a new array variable right before they are sent to hadamrd_transform
. After compiling the model, we can watch the resulting circuit on the Classiq IDE. We see that hadamard_transform
is applied to the qubits specified in the concatenation, namely, the first and last qubits of x1
and the middle two qubits of x2
.

The concatenation operator is not only a convenient feature, but it also helps the programmer to avoid quantum programming bugs. For instance, consider the following model:
@qfunc
def my_control_h(ctrl: QBit, target: QArray):
control(ctrl, lambda: hadamard_transform(target))
@qfunc
def main():
x1 = QArray(length=4)
allocate(x1)
x2 = QArray(length=4)
allocate(x2)
my_control_h(x2[2], [x1[3], x2[1:3], x1[0]])
Function my_control_h
receives a qubit ctrl
and an array target
and applies a controlled Hadamard gate to ctrl
and each qubit of target
. The main
function calls my_control_h
with x2[2]
as the control and a concatenation [x1[3], x2[1:3], x1[0]]
as the target. When we compile the program, we get the following error:
Quantum cloning violation: Arguments 'x2[2]' and 'x2[1:3]' overlap
(This error points to the my_control_h
call.)
Using the same qubit in two different arguments of a quantum gate is not feasible in quantum computation. In the my_control_h
call, the qubit of the first argument x2[2]
also appears in the concatenation, as the second qubit of x2[1:3]
. This has to be a mistake! The Qmod compiler detects this violation and reports an error.
Currently, concatenations are only supported in function call arguments.