How to use Qiskit with QuICScript

Jonathan Liu

The Qiskit-to-QuICScript Translator supports the conversion of these 13 quantum gates into QuICScript. U, I, X, Y, Z, H, S, T, ry, CN, CP, CU, and CCN. The article demonstrates how to convert Qiskit code into QuICScript, showcasing two real-world examples: the Bell state and Quantum Fourier Transform (QFT) circuits.

Introduction

This how-to guide demonstrates how to get started using the qiskit_quicscript_translator to convert Qiskit code to QuICScript. 

This article explains the operations supported by the QuICScript Translator and demonstrates its use with two real-world sample circuits.

We will be using vscode version 1.96.2, Python 3.10.12, qiskit version 1.3.1, and translator version 0.0.1-beta.2. 

As of this release, these are the gates supported: 

Single-qubit quantum gates

  • U gate (ry gate)
  • Identity gate
  • Pauli gates (X,Y,Z)
  • Clifford gates (H,S)
  • C3 gates (T)
  • Standard rotation gate (Rotation around Y-axis) 

Two-qubit quantum gates

  • CN gate
  • CP gate
  • CU gate

Three-qubit gates

  • CCN gate

Pre-requisites

python

1. cd test

2. python3 -m venv .translator 

3. source .translator/bin/activate

4. pip install git+https://github.com/pqcee/qiskit_quicscript_translator@0.0.1-beta.2

5. pip install qiskit==1.3.1

Next steps: When install is complete open vscode, create test.ipynb, and paste the following code blocks.  

python

import numpy as np
from math import pi

from qiskit import QuantumCircuit, QuantumRegister
from qiskit_quicscript_translator import get_quic_circuit_string   

U gate

python

qc = QuantumCircuit(q)
qc.u(pi/2,pi/4,pi/8,q)
get_quic_circuit_string(qc)   # Expected 'U:'

Identity gate

python

qc = QuantumCircuit(q)
qc.id(q)
get_quic_circuit_string(qc)   # Expected 'I:'

X bit-flip gate

python

qc = QuantumCircuit(q)
qc.x(q)
get_quic_circuit_string(qc)   # Expected 'X:'

Y bit-phase flip gate

python

qc = QuantumCircuit(q)
qc.y(q)
get_quic_circuit_string(qc)   # Expected 'Y:'

Z phase-flip gate

python

qc = QuantumCircuit(q)
qc.z(q)
get_quic_circuit_string(qc)   # Expected 'Z:'

Hadamard gate 

python

qc = QuantumCircuit(q)
qc.h(q)
get_quic_circuit_string(qc)    # Expected 'H:'

S gate

python

qc = QuantumCircuit(q)
qc.s(q)
get_quic_circuit_string(qc)   # Expected 'S:'

T gate

python

qc = QuantumCircuit(q)
qc.t(q)
get_quic_circuit_string(qc)   # Expected 'T:'

Rotation around Y-axis

python

qc = QuantumCircuit(q)
qc.ry(pi/2,q)
get_quic_circuit_string(qc)   # Expected 'U:'

Controlled operations on qubits

A common multi-qubit gate involves the application of a gate to one qubit, conditioned on the state of another qubit. For instance, we might want to flip the state of the second qubit when the first qubit is in |0>. Such gates are known as controlled gates.

python

q = QuantumRegister(2)

Two-qubit gates

python

qc = QuantumCircuit(q)
qc.cx(q[0],q[1])
get_quic_circuit_string(qc)   # Expected 'CN:'

python

qc = QuantumCircuit(q)
qc.cp(pi/2,q[0], q[1])
get_quic_circuit_string(qc)   # Expected 'CP:'

python

qc = QuantumCircuit(q)
qc.cu(pi/2, pi/2, pi/2, 0, q[0], q[1])
get_quic_circuit_string(qc)    # Expected 'CU:'

Three-qubit gates

python

q = QuantumRegister(3)

qc = QuantumCircuit(q)
qc.ccx(q[0], q[1], q[2])
get_quic_circuit_string(qc)   # Expected 'CCN:'

Sample Circuits

  • Bell State
  • QFT Circuit

python

# Bell State 

from qiskit import QuantumRegister, ClassicalRegister
from qiskit import QuantumCircuit
from qiskit_quicscript_translator import get_quic_circuit_string

q = QuantumRegister(2,'q')
c = ClassicalRegister(2,'c')

def bellState():
    circuit = QuantumCircuit(q,c)

    circuit.h(q[0]) # Hadamard gate 
    circuit.cx(q[0],q[1]) # CNOT gate
    circuit.measure(q,c) # Qubit Measurment

    print(circuit)
    
    return circuit

print("Qiskit Bell Circuit:\n")
circuit = bellState()
print("QuICScript Bell circuit: " + get_quic_circuit_string(circuit))

Expected Output

QuICScript Bell circuit: HI,CN

Press 'Run' to see the results!

python

# QFT circuit

import numpy as np
from numpy import pi
# importing Qiskit
from qiskit import QuantumCircuit
from qiskit_quicscript_translator import get_quic_circuit_string

def QFT():
    qc = QuantumCircuit(3)
    qc.h(2)
    qc.cp(pi/2, 1, 2) # CROT from qubit 1 to qubit 2
    qc.cp(pi/4, 0, 2) # CROT from qubit 2 to qubit 0
    qc.h(1)
    qc.cp(pi/2, 0, 1) # CROT from qubit 0 to qubit 1
    qc.h(0)
    # qc.swap(0,2)

    print(qc)

    return qc

print("Qiskit QFT Circuit:\n")
circuit = QFT()
print("QuICScript QFT circuit: " + get_quic_circuit_string(circuit))

Expected Output

QuICScript Bell circuit: IIH,ICP,CIP,IHI,CPI,HII

Press 'Run' to see the results!

References

  • https://github.com/Qiskit/textbook/blob/main/notebooks/ch-algorithms/quantum-fourier-transform.ipynb
  • https://quantumcomputinguk.org/tutorials/introduction-to-bell-states
  • https://github.com/pqcee/qiskit_quicscript_translator/blob/main/examples/test.ipynb

Author

Jonathan Liu

Jonathan Liu is a Product Manager at pQCee. Loves learning and passionate about technology. He's been working in tech for 19 years and 2 years in quantum computing. During the day, he spends his time finding product market fit for QuICScript and QuantumNFT. At night, he codes and dreams of changing the world.

Contributors

Reviewers


Be first to comment
Leave a reply