.. _using_QuICScript: ================================ 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:: _static/FundamentalGates.png :alt: Image for Fundamental Gates ---------------------- 2.4.2 Universal Gates ---------------------- .. image:: _static/UniversalGates.png :alt: Image for Universal Gates ----------------------- 2.4.3 Controlled Gates ----------------------- .. image:: _static/ControlledGates.png :alt: 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:: _static/Measurements.png :alt: Image for Measurements -------------------------- 2.4.5 Circuit Modifiers -------------------------- .. image:: _static/CircuitModifiers.png :alt: Image for CircuitModifiers --------------------------- 2.5 API Reference --------------------------- .. c:function:: 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. .. c:function:: char* QuICScript_setState(int numQubits, unsigned long Value, double Count) Sets the initial quantum state for a quantum circuit. :param int numQubits: The number of qubits used in the quantum circuit. :param unsigned long Value: The integer value used to set the initial quantum state. :param double Count: The probability count used to set the initial quantum state. :return: A string (outString1) that represents the initial quantum state. .. c:function:: char* QuICScript_begin(int numQubits) Initializes the QuICScript engine for a quantum circuit with a specific number of qubits. :param int numQubits: The number of qubits used in the quantum circuit. :return: integer value that represents the success of the initialization. **Example Usage:** .. code-block:: C // 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"; } .. c:function:: 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) :param int numQubits: The number of qubits used in the quantum circuit. :param char* myQuICScript: The string that represents the quantum circuit in QuICScript. :param double X1_real: The real part of the first X gate parameter. :param double X1_imag: The imaginary part of the first X gate parameter. :param double Y1_real: The real part of the first Y gate parameter. :param double Y1_imag: The imaginary part of the first Y gate parameter. :param double X2_real: The real part of the second X gate parameter. :param double X2_imag: The imaginary part of the second X gate parameter. :param double Y2_real: The real part of the second Y gate parameter. :param double Y2_imag: The imaginary part of the second Y gate parameter. :return: A string (outString1) that represents the output of the quantum circuit. **Example Usage:** .. code-block:: C // 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]); .. c:function:: void QuICScript_end() Ends the QuICScript engine for a quantum circuit. **Example Usage:** .. code-block:: C // Resets the state Module._QuICScript_end(); inited = 0; message = "State is cleared."; document.getElementById('quicDisplay').innerHTML = ""; .. c:function:: char* QuICScript_Qibo(int numQubits, char* myQuICScript, double theta, double phi, double lamda) Translates the QuICScript string into Qibo code. :param int numQubits: The number of qubits used in the quantum circuit. :param char* myQuICScript: A string that represents the QuICScript, detailing the quantum circuit's operations. :param double theta: The theta parameter, typically used in rotational quantum gates. :param double phi: The phi parameter, typically used in rotational quantum gates. :param double lamda: The lambda parameter, typically used in rotational quantum gates. :return: Qibo code that represents the quantum circuit. **Example Usage:** .. code-block:: C // 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]);