3. Using QuICScript¶
3.1. Overview¶
This section is designed to get you up and running with QuICScript quickly. It covers the following sections:
Building Circuits: the quantum gates supported in QuICScript.
Circuit Syntax: how to create a quantum circuit in QuICScript.
Results Display: Outputs are shown in QuICScript engine section the Results section and can be formatted in decimal or binary.
Commands Guide: Detailed explanations of fundamental, universal, controlled gates, and measurement operations.
API Reference: Detailed function documentation to interact programmatically with QuICScript.
3.2. QuICScript cheat sheet¶
For a summary of the QuICScript commands for the current version of QuICScript, read the QuICScript Cheat Sheet.
3.3. Building a circuit in QuICScript¶
When building your circuit in QuICScript, supported gates include: X
, Y
, Z
, H
, CN
, P
, T
, I
, m
, J
, and U
.
3.3.1. Circuit syntax¶
The language used to write the quantum program is “QuIC” (Quantum Interpreted Circuits) where the BNF notation of QuIC quantum program is as follows:
::= | ::= | ::= H | C | N | X | Y | Z | P | p | T | t | I | m ::= , | .
The use of QuICScript allows for efficient description and execution of the quantum program which is important since we want to run the quantum program interactively.
The gate operations supported by QuIC are as follows:
Hadamard (H)
Control-Not (CN)
Pauli-X (X)
Pauli-Y (Y)
Pauli-Z (Z)
pi/4 and pi/8 Phase-shift (P, T)
Conjugate pi/4 and pi/8 Phase-shift (p, t)
Identity (I)
measurement (m)
Note: gates are separated by a comma delimiter and a period signifies the end of a circuit.
3.4. Results¶
The results of the circuit is displayed on the Results section on the right hand side of the page.
Note that the results are displayed in decimal. For displaying of results in binary, simply add a : at the end of your circuit.
Example result for HX:
01,50.00%;
11,50.00%;
Note
The percentage value represents the probability of the state. \(|01\rangle\) has a 50% probability, and \(|11\rangle\) has a 50% probability.
3.5. QuICScript Commands¶
The QuICScript Engine supports the execution of many discrete quantum gates. The commands are listed in the left column, and the associated behaviour is listed in the right column.
Types of Gates:
3.5.1. Fundamental Gates¶
QuICScript Command |
Description |
---|---|
|
Identity Gate |
|
Pauli-X Gate |
|
Pauli-Y Gate |
|
Pauli-Z Gate / Phase shift by \(\varphi\) = \(\pi\) |
|
Hadamard Gate |
|
Phase (S, P) Gate / Phase shift by \(\varphi\) = \(\frac{\pi}{2}\) |
|
Inverse Phase (S, P) Gate |
|
Phase (T) Gate / Phase shift by \(\varphi\) = \(\frac{\pi}{4}\) |
|
Inverse Phase (T) Gate |
|
Swap Gate |
3.5.2. Universal Gates¶
QuICScript Command |
Description |
---|---|
|
U Gate. Enables arbitrary rotation of a single qubit. Parameters are the three Euler rotation angles, \(\theta\), \(\varphi\) and \(\lambda\). |
The matrix for the U gate is defined as:
If you wish to implement the rotation operators about the x-axis, y-axis, they can be defined via the U gate as follows:
To implement the phase shift via the U gate, it is defined as:
3.5.3. Controlled Gates¶
QuICScript Command |
Description |
---|---|
|
Controlled Not Gate (CNOT) |
|
Controlled Y Gate |
|
Controlled Z Gate (CZ) |
|
Controlled Phase (S, P) Gate |
|
Controlled Phase (T) Gate |
|
Fredkin Gate (CSWAP) |
|
Controlled U Gate |
|
Toffoli Gate (CCNOT) |
|
n-bit Toffoli Gate |
Similar to the Toffoli gate, QuICScript also supports controlled-controlled-gate syntax for the above listed controlled gates. E.g., CCY
, CYC
, ZCC
, etc.
Note that QuICScript Engine supports any permutation of the QuICScript commands describing the controlled gates.
Similar to the n-bit Toffoli gate, QuICScript also supports n-bit controlled-gate syntax for the above listed controlled gates. E.g., CCCY
, CYCC
, ZCCCC
, etc.
3.5.4. Measurements¶
QuICScript Command |
Description |
---|---|
|
Measurement operation that resolves at random, per execution, according to the quantum state probabilities to either \(| 0 \rangle\) or \(| 1 \rangle\) |
3.5.5. Circuit Modifiers¶
QuICScript Command |
Description |
---|---|
|
One QuICScript command is assigned to each qubit in a top-to-bottom vertical sequence. The comma is a delimiter to indicate that all available qubits have been each assigned a command; the next set of command-to-qubit assignments is expected after the comma. |
|
Delete a qubit from the output state (system wavefunction). The probabilities of the remaining qubits will be normalized in the QuICScript Engine output. |
3.6. API Reference¶
-
void QuICScript_clearbuf()¶
Clears any internal buffers used by the QuICScript engine. This function should be called to reset the state between different QuICScript circuit executions.
-
char *QuICScript_setState(int numQubits, unsigned long Value, double Count)¶
Sets the initial quantum state for a quantum circuit.
- Parameters:
numQubits (int) – The number of qubits used in the quantum circuit.
Value (unsigned long) – The integer value used to set the initial quantum state.
Count (double) – The probability count used to set the initial quantum state.
- Returns:
A string (outString1) that represents the initial quantum state.
-
char *QuICScript_begin(int numQubits)¶
Initializes the QuICScript engine for a quantum circuit with a specific number of qubits.
- Parameters:
numQubits (int) – The number of qubits used in the quantum circuit.
- Returns:
integer value that represents the success of the initialization.
Example Usage:
// Initializes a circuit for the first time var inited = 0; if(inited == 0) { Module._QuICScript_begin(numQubits); inited = numQubits; message = "State is reset, working on " + numQubits + " Qubits\n"; }
-
char *QuICScript_cont(int numQubits, char *myQuICScript, double X1_real, double X1_imag, double Y1_real, double Y1_imag, double X2_real, double X2_imag, double Y2_real, double Y2_imag)¶
- Parameters:
numQubits (int) – The number of qubits used in the quantum circuit.
myQuICScript (char*) – The string that represents the quantum circuit in QuICScript.
X1_real (double) – The real part of the first X gate parameter.
X1_imag (double) – The imaginary part of the first X gate parameter.
Y1_real (double) – The real part of the first Y gate parameter.
Y1_imag (double) – The imaginary part of the first Y gate parameter.
X2_real (double) – The real part of the second X gate parameter.
X2_imag (double) – The imaginary part of the second X gate parameter.
Y2_real (double) – The real part of the second Y gate parameter.
Y2_imag (double) – The imaginary part of the second Y gate parameter.
- Returns:
A string (outString1) that represents the output of the quantum circuit.
Example Usage:
// Executes the Bell state circuit resultstate = Module.ccall("QuICScript_cont", "string", ["number", "string", "number", "number", "number", "number", "number", "number", "number", "number"], [2, "HI,CN", 2,0,0,0,0,0,1,0]);
-
void QuICScript_end()¶
Ends the QuICScript engine for a quantum circuit.
Example Usage:
// Resets the state Module._QuICScript_end(); inited = 0; message = "State is cleared."; document.getElementById('quicDisplay').innerHTML = "<textarea readonly >" + message + "</textarea>";
-
char *QuICScript_Qibo(int numQubits, char *myQuICScript, double theta, double phi, double lamda)¶
Translates the QuICScript string into Qibo code.
- Parameters:
numQubits (int) – The number of qubits used in the quantum circuit.
myQuICScript (char*) – A string that represents the QuICScript, detailing the quantum circuit’s operations.
theta (double) – The theta parameter, typically used in rotational quantum gates.
phi (double) – The phi parameter, typically used in rotational quantum gates.
lamda (double) – The lambda parameter, typically used in rotational quantum gates.
- Returns:
Qibo code that represents the quantum circuit.
Example Usage:
// Generates Qibo code for the Bell State circuit resultstate = Module.ccall("QuICScript_Qibo", "string", ["number", "string", "number", "number", "number"], [2, "HI,CN", 0,0,0]);