Basics

Requirements

  • SpinQit is available on Windows, Linux and MacOS. Only the Windows version can use a local quantum computer as a backend. This package has been tested on Ubuntu 20.04 & 22.04 (x86_64), Windows 10 (x86_64), MacOS Ventura 13.0 (M1, M2) and MacOS Mojave 10.14.6 (x86_64).

  • SpinQit requires Python 3.8+. This package has been tested with Python 3.8.13 and 3.9.12.

  • We suggest you use Anaconda to set up your Python environment. Please refer to https://docs.anaconda.com/anaconda/ about how to install and use a conda environment. On Windows, we recommend adding Anaconda to your PATH environment viarable to avoid unnecessary troubles.

Installation

SpinQit can be installed using the following command:

pip install spinqit

To build from the source on Github, you need a C/C++ compiler and CMake in addition. We do not recommend this way unless you are very familiar with the tools.

First Example

The following example is a simple quantum program using SpinQit Python syntax. You can run it as a Python script.

from spinqit import get_basic_simulator, get_compiler, Circuit, BasicSimulatorConfig
from spinqit import H, CX, Rx
from math import pi

# Write the program
circ = Circuit()
q = circ.allocateQubits(2)
circ << (Rx, q[0], pi)
circ << (H, q[1])
circ << (CX, (q[0], q[1]))

# Choose the compiler and backend
comp = get_compiler("native")
engine = get_basic_simulator()

# Compile
optimization_level = 0
exe = comp.compile(circ, optimization_level)

# Run
config = BasicSimulatorConfig()
config.configure_shots(1024)
result = engine.execute(exe, config)

print(result.counts)

Output:

{'10': 512, '11': 512}

There are three steps in a SpinQit program.

  1. Write the program. The example above shows how to allocate qubits and apply quantum gates to the qubits.

  2. Generate an intermediate representation of the program by compiling it with the appropriate compiler.

  3. Run the code using your preferred backend. The example above uses the basic classical simulator.

More details about the syntaxes, compilers and backends will be introduced in the next section.