79
$\begingroup$

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.

$\endgroup$
3
  • 4
    $\begingroup$ Highly relevant Physics.SE post $\endgroup$
    – Mr. Xcoder
    Commented Mar 12, 2018 at 20:04
  • $\begingroup$ What is the difference between "emulate" and "simulate"? $\endgroup$
    – Edifice
    Commented Jan 2, 2021 at 1:56
  • $\begingroup$ “Given some input, a simulation will provide approx. the same output as the original. Emul provides the same output as the original, and will also process the input in the same way as the original in order to determine its output. we use emul to describe a program or device that is able to fully imitate another. In contrast,a sim is almost identical to the normal function another program or device performs, but does not do so in the way the original program or device does. This may be via some abstract model of what is being simulated; emulation requires faithful reproduction of the object” $\endgroup$ Commented Jan 2, 2021 at 5:23

7 Answers 7

44
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Note that none of these emulators can (currently) be used by Q#, which only works with Microsoft's QDK. $\endgroup$
    – Pavel
    Commented Mar 12, 2018 at 18:26
  • 3
    $\begingroup$ In addition to what you said: There are programatic ways to run code on the IBM Quantum Experience which provides real quantum computers - not Q# code, but QASM instead. QISKit is the way to go here. github.com/QISKit $\endgroup$ Commented Mar 13, 2018 at 6:50
  • $\begingroup$ What you said makes sense because the simulation is run on one computer. But is it possible to achieve the same speed if multiple computers were used? $\endgroup$ Commented Oct 20, 2019 at 1:59
30
$\begingroup$

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

$\endgroup$
1
  • 2
    $\begingroup$ I find myself coming back to Quirk a lot for simple tests. It's a really awesome work, thank you! $\endgroup$ Commented Dec 2, 2019 at 18:31
26
$\begingroup$

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

$\endgroup$
14
$\begingroup$

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".

$\endgroup$
3
$\begingroup$

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.

$\endgroup$
0
0
$\begingroup$

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

$\endgroup$
-3
$\begingroup$

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.

$\endgroup$
1
  • 1
    $\begingroup$ if you want to engage in this sort of self-advertisement, you need to disclose your affiliation with the company. Also, to make this answer useful, please include in the post itself more details (eg how this emulator differs from others, its pros and cons, etc) $\endgroup$
    – glS
    Commented Jul 26 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.