Code Monkey home page Code Monkey logo

pyqubits's Introduction

pyqubits

A Python module for quantum computing simulations.

Setup

$ git clone https://github.com/tombch/pyqubits.git
$ cd pyqubits/
$ conda env create -f environment.yml
$ conda activate pyqubits
$ pip install .

Usage

Creating a QuantumState

>>> from pyqubits import QuantumState
>>> s = QuantumState(3)
>>> t = QuantumState.from_bits('00')

Viewing a QuantumState

>>> s
QuantumState([-0.29615118+0.50152956j,  0.37355584-0.06041027j,
               0.40094705-0.13785654j, -0.17540328-0.25628919j,
              -0.26399075+0.28541768j,  0.11632225-0.12028472j,
               0.08627474-0.14452522j,  0.04189382+0.17920989j])
>>> s.vector
array([-0.29615118+0.50152956j,  0.37355584-0.06041027j,
        0.40094705-0.13785654j, -0.17540328-0.25628919j,
       -0.26399075+0.28541768j,  0.11632225-0.12028472j,
        0.08627474-0.14452522j,  0.04189382+0.17920989j])
>>> print(s)
= (- 0.29615 + 0.50153j) |000> + (  0.37356 - 0.06041j) |001> 
+ (  0.40095 - 0.13786j) |010> + ( - 0.1754 - 0.25629j) |011> 
+ (- 0.26399 + 0.28542j) |100> + (  0.11632 - 0.12028j) |101> 
+ (  0.08627 - 0.14453j) |110> + (  0.04189 + 0.17921j) |111> 
>>> print(s.circuit)
1---
    
2---
    
3---
>>> print(s.dist)
000     0.34    |=================
001     0.14    |=======
010     0.18    |=========
011     0.1     |=====
100     0.15    |========
101     0.03    |=
110     0.03    |=
111     0.03    |==
>>> t
QuantumState([1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j])
>>> t.vector
array([1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j])
>>> print(t)
= (1 + 0j) |00> 
>>> print(t.circuit)
1---
    
2---
>>> print(t.dist)
00      1.0     |==================================================
01      0.0     |
10      0.0     |
11      0.0     |

Manipulating a QuantumState

>>> t.H(1)
QuantumState([0.70710678+0.j, 0.        +0.j, 0.70710678+0.j, 0.        +0.j])
>>> t.CNOT(1, 2)
QuantumState([0.70710678+0.j, 0.        +0.j, 0.        +0.j, 0.70710678+0.j])
>>> print(t)
= (0.70711 + 0j) |00> + (0.70711 + 0j) |11> 
>>> print(t.circuit)
1---H---O---
        |   
2-------X---
>>> print(t.dist)
00      0.5     |=========================
01      0.0     |
10      0.0     |
11      0.5     |=========================
>>> t.measure(1)
QuantumState([1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j])
>>> result = t.bit
>>> result
0
>>> print(t)
= (1 + 0j) |00>

pyqubits's People

Contributors

tombch avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.