qsharp-community / qram

Licence: MIT license
Library for Q# implementing various qRAM proposals

Programming Languages

Q#
14 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to qram

QuantumResources
A collection of resources for Quantum Computing
Stars: ✭ 43 (-6.52%)
Mutual labels:  quantum-computing, quantum-development-kit, qdk
Quantum
Microsoft Quantum Development Kit Samples
Stars: ✭ 3,453 (+7406.52%)
Mutual labels:  quantum-computing, quantum-development-kit, qdk
Quantum-Machine-Learning
This repository contains implementations of Quantum Machine Learning algorithms, feature maps, variational circuits and research papers.
Stars: ✭ 47 (+2.17%)
Mutual labels:  quantum-computing, quantum-machine-learning
unitaryhack
Rules and information for the 2021 unitaryHACK event hosted by @unitaryfund
Stars: ✭ 16 (-65.22%)
Mutual labels:  quantum-computing, quantum-machine-learning
launchpad
Resources to get started in Quantum Computing!
Stars: ✭ 21 (-54.35%)
Mutual labels:  quantum-computing, quantum-machine-learning
iqsharp
Microsoft's IQ# Server.
Stars: ✭ 112 (+143.48%)
Mutual labels:  quantum-development-kit, qdk
cusp cirq demo
Demonstration of CUSP algorithm using Cirq
Stars: ✭ 35 (-23.91%)
Mutual labels:  quantum-computing, quantum-machine-learning
learn-qc-with-python-and-qsharp
Companion code for Learn Quantum Computing with Python and Q# Book by Dr. Sarah Kaiser and Dr. Chris Granade 💖
Stars: ✭ 62 (+34.78%)
Mutual labels:  quantum-computing, quantum-development-kit
quantumcat
quantumcat is a platform-independent, open-source, high-level quantum computing library, which allows the quantum community to focus on developing platform-independent quantum applications without much effort.
Stars: ✭ 18 (-60.87%)
Mutual labels:  quantum-computing, quantum-library
Awesome Quantum Machine Learning
Here you can get all the Quantum Machine learning Basics, Algorithms ,Study Materials ,Projects and the descriptions of the projects around the web
Stars: ✭ 1,940 (+4117.39%)
Mutual labels:  qml, quantum-computing
Qml
Introductions to key concepts in quantum machine learning, as well as tutorials and implementations from cutting-edge QML research.
Stars: ✭ 174 (+278.26%)
Mutual labels:  qml, quantum-computing
Quantum-Computing-Resources
This repository contains the best resources for learning practical quantum computing. This repository will be updated frequently.
Stars: ✭ 60 (+30.43%)
Mutual labels:  quantum-computing, quantum-machine-learning
QuAlgorithmZoo.jl
A curated implementation of quantum algorithms with Yao.jl
Stars: ✭ 78 (+69.57%)
Mutual labels:  quantum-computing, quantum-machine-learning
QCompress-1
Quantum Autoencoder Implementation using Forest and OpenFermion
Stars: ✭ 20 (-56.52%)
Mutual labels:  quantum-computing, quantum-machine-learning
IBM-Quantum-QCE20-Tutorials
Repository of code notebooks for tutorials at IEEE Quantum Week (QCE20) https://qce.quantum.ieee.org/tutorials/
Stars: ✭ 38 (-17.39%)
Mutual labels:  quantum-computing, quantum-machine-learning
osm
Open sound meter. FFT based application for tuning sound systems.
Stars: ✭ 122 (+165.22%)
Mutual labels:  qml
neural-decoder
Neural Network Decoders for Quantum Error Correcting Codes
Stars: ✭ 19 (-58.7%)
Mutual labels:  quantum-computing
avaloni
Interpreter of the Avalon programming language.
Stars: ✭ 14 (-69.57%)
Mutual labels:  quantum-computing
qml-glsl-coder
live editor of GLSL fragment shaders based on Qt / QML
Stars: ✭ 19 (-58.7%)
Mutual labels:  qml
Project-Template
A template for modern C++ projects with useful features for developing cross-platform products.
Stars: ✭ 44 (-4.35%)
Mutual labels:  qml

qRAM Library for Q#

Unitary Fund

This library implements a variety of different proposals for memory for quantum computers, also commonly called qRAM.

Want to learn more about what qRAM is? Check out the primer on memory for quantum computers in our docs!

Motivation

There are many different proposals for qRAM in quantum computing that each have different tradeoffs, and currently come up a lot in quantum machine learning applications. We want to better understand the costs and benefits of different qRAM implementations in quantum machine learning as well as quantum computing more generally. This library will help achieve these goals by giving us a concrete way to measure the resources each approach takes; choosing to do this in Q# allows us to leverage the built-in resource estimator to quickly iterate profiling the qRAM implementations and optimizing the circuits.

FAQ:

  • Do I need a qRAM?

    Sometimes. You'll need a qRAM, or some more general means of quantum state preparation in quantum machine learning (QML) algorithms that require you to load in classical data, or query an oracle that returns classical data. I've heard a number of stories of people working on QML being actively discouraged from doing so because ``QML won't work without a qRAM''. That's just not true, because many QML algorithms do not need a qRAM. Now, whether or not they yield any quantum advantage is a separate question, and won't be discussed here. The key point is that some QML algorithms need a qRAM, and they will potentially run into trouble as per the next question.

  • Can we design an efficient qRAM?

    Maybe. In the primer we'll take a look at proposals that will in principle run in polynomial depth, and others that scale far worse. There are some very interesting qubit-time tradeoffs one can explore, in particular if the data being stored has some sort of underlying structure. Regardless, even if we can design an efficient circuit, we'd also like something that is efficient in a fault-tolerant setting, and this is potentially very expensive.

  • Can I build one?

    Maybe. No one has actually done so, but there are a handful of hardware proposals that will be discussed in more detail in the hardware section of the primer on memory for quantum computers.

Build status

Run Tests Build and publish NuGet package to GitHub packages

Code style

q# code style q# APIcode style c# APIcode style CoC

Screenshots

Example of a Bucket Brigade qRAM circuit: TODO: Q# notebook screenshots/gif TODO: Source in VS Code/gif

Bucket Brigade qRAM

Tech/framework used

Built with:

Features

This library implements a variety of different approaches for qRAM and qROM, including:

  • Bucket Brigade qRAM: A read/write style memory where specific qubits are set aside to hold the data in the memory. The information can be queried so that the data returned is either bit encoded or phase encoded.

  • qROM: A read-only style memory that creates a fixed operation that given an address and a target, encodes the data at that address on the target. qROMs are like quantum lookup tables.

  • SELECT-SWAP qROM: A read-only style memory similar to the basic qROM but that has multiplexing optimizations that can help you adjust your program resources.

It is important to us that we come up with an extensible framework for implementing as many qRAM/qROM implementation as possible so we can have a uniform way to evaluate and compare these proposals. We also include a sample for doing resource estimation (and not actually simulating) so that you can get an idea of what the resources are needed to run your memory.

To validate the qRAM/qROM implementations in this library, this library includes unit tests for small memories that can be simulated classically.

This library is highly portable, and can easily be added to any Q# project with just a package include in your project file! Check out the instructions below for adding the qRAM library to your project.

Code Example

Creating and then measuring a read-only memory:

operation QromQuerySample(queryAddress : Int) : Int {
    // Generate a (Int, Bool[]) array of data.
    let data = GenerateMemoryData();
    // Create the QRAM.
    let memory = QromOracle(data::DataSet);
    // Measure and return the data value stored at `queryAddress`.
    return QueryAndMeasureQROM(memory, queryAddress);
}

See Qrom sample for the rest of this implementation!

Using a phase query Bucket Brigade QRAM to reflect about a marked state:

operation GroverSearch(addressSize : Int, markedElements : Int[]) : Int {
  // First, set up a qRAM with marked elements set to 1.
  let nMarkedElements = Length(markedElements);
  mutable groverMemoryContents = Mapped<Int,MemoryCell>(MemoryCell(_, [false]), RangeAsIntArray(0..2^addressSize - 1));

  // Set the data value to true for each marked address.
  for (markedElement in markedElements) {
    set groverMemoryContents w/= markedElement <- MemoryCell(markedElement, [true]);
  }

  using ((groverQubits, targetQubit, flatMemoryRegister) =
      (Qubit[addressSize], Qubit[1], Qubit[2^addressSize])
  ) {
        // Create a structured register to make indexing through the memory easier.
        let memoryRegister = PartitionMemoryRegister(
            flatMemoryRegister,
            GeneratedMemoryBank(groverMemoryContents)
        );
        // Prepare the memory register with the initial data.
        let memory = BucketBrigadeQRAMOracle(groverMemoryContents, memoryRegister);

        // Initialize a uniform superposition over all possible inputs.
        PrepareUniform(groverQubits);

        // Grover iterations - the reflection about the marked element is implemented
        // as a QRAM phase query. Only the memory cells storing a 1 will produce a phase.
        for (idxIteration in 0..NIterations(nMarkedElements, addressSize) - 1) {
          
          memory::QueryPhase(AddressRegister(groverQubits), memoryRegister, targetQubit);
          ReflectAboutUniform(groverQubits);

          // It's necessary to remove phase since QueryPhase only sets phase
          // on the specific address instead of inverting like traditional Grover's.
          ApplyToEach(Z, targetQubit);
          ResetAll(targetQubit);
        }
        ResetAll(flatMemoryRegister);

    // Measure and return the answer.
    ResetAll(targetQubit);
    return MeasureInteger(LittleEndian(groverQubits));
  }
}

See the Grover sample for the rest of this implementation!

TODO: #37

Installation

Anywhere you can use Q#, you can use this library!

  • Python host program
  • Jupyter Notebooks
  • Stand-alone command line application
  • C#/F# host program

For complete and up-to-date ways to install the Quantum Development Kit (including Q# tooling) see the official Q# docs.

For convenience, in this repo we include the following ways to make it easier to use this project.

  • Remote Development Environment (VS Code)
    • Once you open this repo in VS Code, you should be able to open the command pallet and select Remote-Containers: Reopen in Container and your editor will re-launch in a local docker container that will be properly configured to use the project.
  • Binder in-browser host (Web): TODO: Test

API Reference

TODO: See #27

Tests

The tests for this library all live in the tests directory. To run the tests, navigate to that directory and run dotnet test and the .NET project will find and run all the tests in this directory. If you are adding new features or functionality, make sure to add some tests to either the existing files, or make a new one. For more info on writing tests for Q#, check out the official Q# docs.

How to use?

You want to use a published version of the library package:

TODO: more detail on nuget.org stuff once published there.

For more information on adding packages to Q# projects (the instructions are the same as for C# packages) check out the official docs.

You want to work on developing the library and use a locally built version of the project:

The basic idea in this case is build locally a version of the nuget packages and then put it in a folder locally that is a known source to nuget.

  1. Remove any previous copies of the package from your local nuget feed (you likely picked this location), and global nuget cache (default path on Windows 10 for the cache is below):
> rm C:\Users\skais\nuget-packages\QSharpCommunity.Libraries.Qram.X.X.X.nupkg
> rm C:\Users\skais\.nuget\packages\QSharpCommunity.Libraries.Qram\
  1. Build the package for the Qram library:
> cd src
> dotnet pack
  1. Copy the package to your local nuget source (a location you selected, an example one is below). The X in the name are the place holder for the version number you are building (should be generated by the previous step).
> cp .\bin\Debug\QSharpCommunity.Libraries.Qram.X.X.X.nupkg 'C:\Users\skais\nuget-packages\'

Contribute

Please see our contributing guidelines and our code of conduct before working on a contribution, thanks!

Credits

  • Primary developers: @glassnotes, @crazy4pi314
  • Code review and API design assistance: @RolfHuisman, @cgranade, @amirebrahimi

Anything else that seems useful

License

MIT © qsharp-community

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].