GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ken-nakanishi/qupy: QuPy: Quantum circuit simulator for both CPU and GPU

BranchesTags
Open more actions menu

Latest commit

 

History

103 Commits
103 Commits

Folders and files

NameName
Last commit message
Last commit date
docs
docs
 
 
qupy
qupy
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
README.md
README.md
 
 
setup.py
setup.py
 
 

Repository files navigation

QuPy

Build Status Downloads Downloads Downloads

QuPy is a quantum circuit simulator for both CPU and GPU.

The features of QuPy are as follows.

  • fast: You can experiment with your idea quickly!
  • simple: You can experiment with your idea easily!

QuPy supports both Python 3 and Python 2.

QuPy uses CuPy to support GPU.

Install

pip install qupy

or

pip3 install qupy

or

conda install conda-forge::qupy

GPU

If you use a GPU, install cupy and set the following environment variables.

  • QUPY_DTYPE
    • Data type of the data array.
    • complex64 or complex128 or complex256
    • If you does not set QUPY_DTYPE, Data type is set complex128.
  • QUPY_GPU
    • GPU machine number (integer).
    • Set QUPY_GPU if you use GPU.
    • If you don't set QUPY_GPU or you set QUPY_GPU=-1, your program will be running on the CPU.

Read the CuPy documentation for using CuPy.

Documents

https://qupy.readthedocs.io/en/latest/qupy.html

Development

Your contribution is welcome!

Example

>>> import numpy as np
>>> from qupy import Qubits
>>> from qupy.operator import H, X, rz, swap

>>> q = Qubits(3)
>>> print(q.get_state())
[1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]

>>> q.gate(H, target=0)
>>> q.gate(H, target=1)
>>> print(q.get_state())
[0.5+0.j 0. +0.j 0.5+0.j 0. +0.j 0.5+0.j 0. +0.j 0.5+0.j 0. +0.j]

>>> q.set_state('011')
>>> print(q.get_state())
[0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]

>>> q.gate(X, target=2)
>>> print(q.get_state())
[0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]

>>> q.set_state([0, 1, 0, 0, 0, 0, 0, 0])
>>> print(q.get_state())
[0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]

>>> q.gate(X, target=2)
>>> print(q.get_state())
[1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]

>>> q.gate(H, target=0)
>>> q.gate(H, target=1)
>>> q.gate(X, target=2, control=(0, 1))
>>> q.gate(X, target=0, control=1, control_0=2)
>>> q.gate(swap, target=(0, 2))
>>> q.gate(rz(np.pi / 8), target=2, control_0=1)
>>> print(q.get_state())
[0.49039264-0.09754516j 0.49039264+0.09754516j 0.        +0.j
 0.5       +0.j         0.        +0.j         0.        +0.j
 0.        +0.j         0.5       +0.j        ]

>>> iswap = np.array([[1, 0, 0, 0],
...                   [0, 0, 1j, 0],
...                   [0, 1j, 0, 0],
...                   [0, 0, 0, 1]])

>>> q.gate(iswap, target=(2, 1))
>>> print(q.get_state())
[ 0.49039264-0.09754516j  0.        +0.j         -0.09754516+0.49039264j
  0.5       +0.j          0.        +0.j          0.        +0.j
  0.        +0.j          0.5       +0.j        ]

>>> res = q.project(target=0)
>>> print(res)
0
>>> print(q.get_state())
[ 0.56625665-0.11263545j  0.        +0.j         -0.11263545+0.56625665j
  0.57735027+0.j          0.        +0.j          0.        +0.j
  0.        +0.j          0.        +0.j        ]

>>> q.gate(H, target=1)
>>> q.gate(swap, target=(2, 0), control=1)
>>> print(q.get_state())
[ 0.32075862+0.32075862j  0.40824829+0.j          0.4800492 -0.4800492j
  0.        +0.j          0.        +0.j          0.        +0.j
 -0.40824829+0.j          0.        +0.j        ]

>>> res = q.project(target=1)
>>> print(res)
1
>>> print(q.get_state())
[ 0.        +0.j          0.        +0.j          0.60597922-0.60597922j
  0.        +0.j          0.        +0.j          0.        +0.j
 -0.51534296+0.j          0.        +0.j        ]

>>> hamiltonian = {'XXI': 1, 'IIZ': -0.5}
>>> print(q.expect(hamiltonian))
-0.4999999999999999
>>> hamiltonian = np.kron(np.kron(X, X), X)
>>> print(q.expect(hamiltonian))
0.0

Citation

@Misc{QuPy,
  author = {Nakanishi, Ken M},
  title = {{QuPy}: A quantum circuit simulator for both CPU and GPU},
  year = {2018--},
  url = "https://github.com/ken-nakanishi/qupy",
  note = {[Online; accessed <today>]}
}

License

MIT License (see LICENSE file).

About

QuPy: Quantum circuit simulator for both CPU and GPU

Resources

Readme
MIT license
Activity

Stars

45 stars

Watchers

4 watching

Forks

8 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.