Basics¶
Requirements¶
SpinQit is available on Windows, Linux, and macOS. This package has been tested on Ubuntu 20.04 & 22.04 (x86_64), Windows 10 & 11 (x86_64), macOS Ventura 13.0 (M1), macOS Sonoma 14.6.1 (M2), and macOS Big Sur 11.0 (x86_64).
SpinQit requires Python 3.8, 3.9 or 3.10. This package has been tested with Python 3.8.13, 3.9.12, and 3.10.20.
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 approach unless you are very familiar with these 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.
Write the program. The example above shows how to allocate qubits and apply quantum gates to the qubits.
Generate an intermediate representation of the program by compiling it with the appropriate compiler.
Run the code using your preferred backend. The example above uses the basic classical simulator.
More details about the syntax, compilers, and backends are introduced in the next section.