80

Is there any way to emulate a quantum computer in my normal computer, so that I will be able to test and try quantum programming languages (such as Q#)? I mean something that I can really test my hypothesis and gets the most accurate results.

Update: I'm not really looking for simulating a quantum computer, but I'm not sure if its possible to efficiently emulate one on a normal non-quantum based PC.

Sanchayan Dutta
  • 17,945
  • 8
  • 50
  • 112
Michel Gokan Khan
  • 911
  • 1
  • 8
  • 10

7 Answers7

45

Yes, it's possible (but slow). There are a couple of existing (this is only a partial list) emulators:

  • QDD: A Quantum Computer Emulation Library

    QDD is a C++ library which provides a relatively intuitive set of quantum computing constructs within the context of the C++ programming environment. QDD is unique in that the its emulation of quantum computing is based upon a Binary Decision Diagram (BDD) representation of the quantum state.

  • jQuantum

    jQuantum is a program which simulates a quantum computer. You can design quantum circuits with it and let them run. The current state of the quantum register is illustrated.

  • QCE

    QCE is a software tool that emulates various hardware designs of Quantum Computers. QCE simulates the physical processes that govern the operation of a hardware quantum processor, strictly according to the laws of quantum mechanics. QCE also provides an environment to debug and execute quantum algorithms under realistic experimental conditions.

(In addition, Q# only works with MS's QDK, thanks @Pavel)

The downside to all of these is simple: they still run on binary (non-quantum) circuits. To the best of my knowledge, there's no easily accessible quantum computer to use for running these things. And since it takes multiple binary bits to express a single qubit, the amount of computational power needed to simulate a quantum program gets large very quickly.

I'll quote a paper on the subject (J. Allcock, 2010):

Our evaluation shows that our implementations are very accurate, but at the same time we use a significant amount of additional memory in order to achieve this. Reducing our aims for accuracy would allow us to decrease representation size, and therefore emulate more qubits with the same amount of memory.

p 89, section 5.1

As our implementations get more accurate, they also get slower.

TL;DR: it's possible, and some emulators exist, but none are very efficient for large amounts of qubits.

30

Yes, it is possible to simulate quantum computations on a classical computer. But the cost of simulations grows exponentially with qubit count and/or circuit depth and/or particular operation counts.

For trying ideas quickly, my simulator Quirk is great. It's an open-source drag-and-drop quantum circuit simulator that runs in your web browser. You can access a live version at algassert.com/quirk.

Here is a screenshot of Quirk's example Grover circuit, which is instrumented with intermediate state displays to track the "hidden" state becoming more likely:

Screenshot of Quirk

Craig Gidney
  • 44,299
  • 1
  • 41
  • 116
26

Yes, it is possible to simulate a quantum computer on a normal one – But you most likely have to sacrifice efficiency.

The dimension of the state space rises exponentially with the number of qubits ($2^n$, where $n$ is the number of qubits), so the linear algebra you will be dealing with won't be too light – You'll encounter very large matrices and the algorithm you use (regardless of how efficient it is) will likely become exponentially-scaling pretty fast. However, emulating a QC on a normal machine is definitely possible.


Resources

You may be interested in Q# as other answers noted. Some more emulators:

  • Quantum Computing Playground

    Quantum Computing Playground is a browser-based WebGL Chrome Experiment. It features a GPU-accelerated quantum computer with a simple IDE interface, and its own scripting language with debugging and 3D quantum state visualization features. Quantum Computing Playground can efficiently simulate quantum registers up to 22 qubits, run Grover's and Shor's algorithms, and has a variety of quantum gates built into the scripting language itself.

  • QX Simulator

    The QX Simulator is a universal quantum computer simulator developped at QuTech by Nader Khammassi. The QX allows quantum algorithm designers to simulate the execution of their quantum circuits on a quantum computer. The simulator defines a low-level quantum assembly language namely Quantum Code which allows the users to describe their circuits in a simple textual source code file. The source code file is then used as the input of the simulator which executes its content.

  • Quantum++

    Quantum++ is a modern C++11 general purpose quantum computing library, composed solely of template header files. Quantum++ is written in standard C++11 and has very low external dependencies, using only the Eigen 3 linear algebra header-only template library and, if available, the OpenMP multi-processing library.

  • Quantum Computer Language

    Despite many common concepts with classical computer science, quantum computing is still widely considered as a special discipline within the broad field of theoretical physics. [...] QCL (Quantum Computation Language) tries to fill this gap: QCL is a high level, architecture independent programming language for quantum computers, with a syntax derived from classical procedural languages like C or Pascal. This allows for the complete implementation and simulation of quantum algorithms (including classical components) in one consistent formalism.

  • More relevant emulators can be found on Quantiki

Mr. Xcoder
  • 363
  • 4
  • 11
14

If you're specifically looking at Q#, then it's super easy to use with an emulator -- in fact, it's not possible to have Q# but not have the emulator, they're bundled together.

To get started, first you need to download .NET Core from Microsoft's website.

When you download Microsoft's Quantum Development Kit through dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.2-*" or Microsoft's website, it downloads both the language and Microsoft's own emulator together.

Creating a new Q# project (dotnet new console -lang Q#) will automatically configure it to use the emulator, so when you type in some Q# and run the project it "just works".

Pavel
  • 241
  • 1
  • 8
3

I think a nice "overview" about the subject can be found at: Quantiki

They have a list of quantum computer simulators in several languages, some of the simulators have been cited here before. However, they keep a list that they update to inform (or try to inform) of the project's status. There are some "libraries" such as:

Haskell

qchas (qchas: A library for implementing Quantum Algorithms) - A library useful for implementing Quantum Algorithms. It contains definitions of Quantum Gates, Qubits.

Python

qubiter : The Qubiter project aims to provide eventually a full suite of tools, written mostly in Python, for designing and simulating quantum circuits on classical computers.

Javascript

jsqis : jsqis, at its core, is a quantum computer simulator written in Javascript. It allows initialization of quantum registers and their manipulation by means of quantum gates.

Daniel Burkhart
  • 583
  • 6
  • 23
Gustavo Banegas
  • 121
  • 1
  • 5
0

Here is my code for simulation of a quantum computer in MatLab: https://www.mathworks.com/matlabcentral/fileexchange/73035-quantum-computer-simulator

Martin Vesely
  • 15,244
  • 4
  • 32
  • 75
-3

Yeah sure.

There are multiple python packages, and software tools that enable simulating quantum programs.

I usually use Classiq (disclaimer - I'm a Classiq employee) as it has both a web-based IDE at (platform.classiq.io) and a Python package. You can see this example of how to simulate it directly in the web-based IDE:

simulating SWAP-test with the Classiq IDE

Most of the noiseless simulators nowadays offers simulating up to 20-30 qubits. The above simulator offers simulating up to 25 qubits, and you can reach out to the Classiq support to receive access to a more advanced simulator that enables simulating up to 30 qubits.

Eden Schirman
  • 45
  • 2
  • 4