2. Using QuICScript

2.1 TL;DR

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.

2.2 QuICScript cheat sheet

For a summary of the QuICScript commands for the current version of QuICScript, read the QuICScript Cheat Sheet.

2.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. See section 2.3.1. for details regarding syntax.

2.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 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) and measurement (m).

Note: gates are separated by a comma delimiter and a period signifies the end of a circuit.

2.3.2 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. For example: HX:

2.4 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.

2.4.1 Fundamental Gates

Image for Fundamental Gates

2.4.2 Universal Gates

Image for Universal Gates

2.4.3 Controlled Gates

Image for Controlled Gates

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.

2.4.4 Measurements

Image for Measurements

2.4.5 Circuit Modifiers

Image for CircuitModifiers

2.5 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]);