Python lib for using isq
Project description
isqdeployer
What is isqdeployer
isqdeployer serves as an Object-Oriented Interface for isq, offering a pure Python alternative that eliminates the need for isq syntax. It also simplifies the installation process, automatically configuring everything required for isqc. Notably, isqdeployer maintains the crucial advantage of optimizing gates at the quantum circuit level, benefiting quantum algorithms.
Installation
Execute the following command without any additional steps.
pip install isqdeployer
Usuage
A simple example
In the following example, we define a quantum circuit with 2 qubits. It implements an H
gate on the second qubit and concludes with a measurement of all qubits.
from isqdeployer import Circuit
cir = Circuit(2) # define a circuit
cir.H(1) # set gate
cir.setMeasurement([0,1]) # set measurement
cir.runJob() # run
The output is: [{'00': 0.4999999999999999, '01': 0.4999999999999999}]
.
A complex example: Rabi oscillation
Consider a single spin (or qubit) initially in the state $|0\rangle$. When subjected to a wave pulse directly along the X-axis, described by an interacting Hamiltonian $H=X$ (Pauli $X$), the qubit state will oscillate between $|0\rangle$ and $|1\rangle$. The following code simulates this experiment.
from isqdeployer import Circuit
from isqdeployer.circuitDeployer import PauliHamDeployer
from isqdeployer.utils.pauliHamiltonian import PauliHamiltonian
import numpy as np
import matplotlib.pyplot as plt
ham = PauliHamiltonian(nq=1) # define a Hamiltonian
ham.setOneTerm(xi=1.0,p=[1]) # Hamiltonian = Pauli X, (0,1,2,3) represents (I,X,Y,Z)
cir = Circuit(
nq=1, # only 1 qubit
workDir="/home/user/Desktop/test", # see how it works by inspecting internal process
isInputArg=True, # use additional parameter (t) to increase the speed of the calculation
) # circuit, init state is |0>
t = cir.getInputArg(FI='F', id=0) # set the circuit to contains a parameter t
dep = PauliHamDeployer(circuit=cir) # use a deployer to implement gates
dep.expHt(
h=ham,
t=t,
N=15, # Suzuki decomposition
)
cir.setMeasurement([0])
Tlist = np.arange(0,10,0.1)# the time range we study
results = cir.runJob(paramList=[{'F':[t]} for t in Tlist ]) # batch submit all jobs
#---- plot
prob0 = [res.get('0',0) for res in results]
plt.plot(Tlist,prob0)
plt.xlabel("Time (t)")
plt.ylabel('Probability $ \langle 0|0\\rangle$')
plt.show()
The plot of the results is shown in the figure below:
Inspect isq code
In the example above, we have set workDir="/home/user/Desktop/test"
. One can observe the intermediate resources in that directory. The original isq file is named resource.isq
.
Backend
Default simulator
In the above examples, the circuit uses a default simulator as a backend. To illustrate this explicitly, please refer to the following example:
from isqdeployer.backend import NumpySimulator
from isqdeployer.circuit import Circuit
backend = NumpySimulator()
cir = Circuit(nq=1,backend=backend)
cir.H(0)
cir.setMeasurement([0])
cir.runJob()
High efficient simulator
If one has a Fortran compiler (such as gfortran) installed on their PC, they can use:
from isqdeployer.backend import fSimulator
backend = fSimulator(nCore=4)
where nCore
can be the number of CPU cores. This parameter (nCore
) can be utilized in most of our simulators.
Real quantum hardware
Currently, we support the connection to the quantum computer offered by QuantumCteK.
from isqdeployer.backend import GuodunBackend
backend = GuodunBackend(login_key="...",)
Other backends
Users can define their own backend (hardware or simulator) by inheriting the basic class:
from isqdeployer.backend.abcBackend import Backend
class YourBackend(Backend):
pass
With this capability, one can connect any backend to isqdeployer
.
More information
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file isqdeployer-0.0.50-py3-none-any.whl
.
File metadata
- Download URL: isqdeployer-0.0.50-py3-none-any.whl
- Upload date:
- Size: 43.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b37cf819dbdbded782556e25838d20c6499f7bd979584ac0bfbcc1aeabbd3592 |
|
MD5 | 4bde49ce132dcb9b2adaf1418deadd77 |
|
BLAKE2b-256 | 248d2b7db8cd511e75dbba0a0388fcb70b173d950d60226387a9123fa53d9281 |