Giter Club home page Giter Club logo

xacc's Introduction

XACC

Branch Status
master Linux CI Mac CI
devel Linux CI Mac CI

Language and Hardware Independent Quantum Programming Framework

XACC is an extensible compilation framework for hybrid quantum-classical computing architectures. It provides extensible language frontend and hardware backend compilation components glued together via a novel quantum intermediate representation. XACC currently supports quantum-classical programming and enables the execution of quantum kernels on IBM, Rigetti, and D-Wave QPUs, as well as a number of quantum computer simulators.

Documentation

Quick Start

Click Gitpod Ready-to-Code to open up a pre-configured Eclipse Theia IDE. You should immediately be able to run any of the C++ or Python examples from the included terminal:

[example C++ executables are in build/quantum/examples/*]
$ build/quantum/examples/qasm/deuteron_from_qasm

[example Python scripts are in python/examples/*]
$ python3 python/examples/deuteronH2.py

[run some XACC benchmarks]
$ python3 -m xacc --benchmark python/benchmark/chemistry/benchmarks/nah_ucc1.ini 

All code is here and you can quickly start developing. We recommend turning on file auto-save by clicking File > Auto Save . Note the Gitpod free account provides 100 hours of use for the month, so if you foresee needing more time, we recommend our nightly docker images.

The XACC nightly docker images also serve an Eclipse Theia IDE on port 3000. To get started, run

$ docker run --security-opt seccomp=unconfined --init -it -p 3000:3000 ghcr.io/eclipse/xacc/xacc:latest

Navigate to https://localhost:3000 in your browser to open the IDE and get started with XACC.

Build from Source

Full installation details can be followed here.

Ensure that you have installed CMake 3.12+, a C++17 compliant compiler (GCC 8+, Clang 5+), and CURL development headers and libraries with OpenSSL support (see prerequisites).

It is also recommended (though optional) that you install BLAS and LAPACK development libraries (for various simulators), Python 3 development headers (for the Python API), and Libunwind (for stack trace printing).

To enable XACC Python support, ensure that python3 is set to your desired version of Python 3. CMake will find the corresponding development headers. Ensure that when you try to run XACC-enabled Python scripts you are using the same python3 executable that was set during your build.

Clone the repository recursively, configure with cmake and build with make

$ git clone https://github.com/eclipse/xacc
$ cd xacc && mkdir build && cd build
[default cmake call]
$ cmake ..
[with tests and examples]
$ cmake .. -DXACC_BUILD_EXAMPLES=TRUE -DXACC_BUILD_TESTS=TRUE
[now build xacc]
$ make install
[for a speedier build on linux]
$ make -j$(nproc --all) install
[and on mac os x]
$ make -j$(sysctl -n hw.physicalcpu) install
[if built with tests, run them]
$ ctest --output-on-failure

CMake options:

  • XACC_DEPS_EXTERNAL: [Optional, default = OFF] XACC to search externally for its third-party dependencies. When turning on, XACC will try to use find_package to locate its required dependencies before falling back to using the builtin submodules in tpls.

    Note: when turning on this flag, it is your responsibility to manage the compatibility of those tpls. For example, XACC compilation may fail if the externally-installed library version is incompatible with the builtin one.

See full documentation for all CMake optional arguments.

Your installation will be in $HOME/.xacc. If you built with the Python API, be sure to update your PYTHONPATH environment variable to point to the installation:

$ export PYTHONPATH=$PYTHONPATH:$HOME/.xacc

You will probably want the XACC default simulator, TNQVM. To install, run the following:

$ git clone https://github.com/ornl-qci/tnqvm
$ cd tnqvm && mkdir build && cd build
$ cmake .. -DXACC_DIR=~/.xacc
$ make install

Questions, Bug Reporting, and Issue Tracking

Questions, bug reporting and issue tracking are provided by GitHub. Please report all bugs by creating a new issue with the bug tag. You can ask questions by creating a new issue with the question tag.

License

XACC is dual licensed - Eclipse Public License and Eclipse Distribution License.

Cite XACC

If you use XACC in your research, please use the following citation

@article{xacc_2020,
	doi = {10.1088/2058-9565/ab6bf6},
	url = {https://doi.org/10.1088%2F2058-9565%2Fab6bf6},
	year = 2020,
	month = {feb},
	publisher = {{IOP} Publishing},
	volume = {5},
	number = {2},
	pages = {024002},
	author = {Alexander J McCaskey and Dmitry I Lyakh and Eugene F Dumitrescu and Sarah S Powers and Travis S Humble},
	title = {{XACC}: a system-level software infrastructure for heterogeneous quantum{\textendash}classical computing},
	journal = {Quantum Science and Technology}
}

xacc's People

Contributors

1tnguyen avatar acastanedam avatar amccaskey avatar amrutn avatar angusmingare avatar ausbin avatar czhao39 avatar danclaudino avatar dmitrylyakh avatar flatslm avatar jeriimiah avatar joehellmers avatar kharazity avatar mileschen360 avatar nmoran avatar rsand17 avatar rsoftone avatar spowers avatar travishumble avatar wrathfulspatula avatar zpparks314 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xacc's Issues

Compiler computing model vs Accelerator computing model

From @amccaskey on September 27, 2017 13:54

We should add a method to Compiler that returns the model of quantum computing the Compiler works for. We can then perform a check at Program.build time that validates that the given Compiler and Accelerator are compatible.

Copied from original issue: ORNL-QCI/xacc#57

Move pyxacc.py to xacc.py

This just occured to me.

Previously we had to name our python module pyxacc because the Pybind11 library had to be pyxacc.so because we already had an xacc.so. Now that we have a wrapper python module script pyxacc.py that imports _pyxacc.so, we can rename this to xacc.py

Investigate automatic language detection for Compiler selection

From @amccaskey on September 27, 2017 14:9

We could do this in a fairly straightforward way

  • Implement python scikit-learn feature extraction vector
  • Create large set of random circuits in various languages
  • Train feature extraction on that set
  • Integrate with xacc::Program.build() and friends

Copied from original issue: ORNL-QCI/xacc#59

Mac and Linux Python Wheels

We need to create binary builds as python wheels to make it easy for users to pip install xacc and friends.

IBM rest API communication issues

Below are two examples of HTTP status line issues I have encountered in the last 24 hrs.

EX1:
Job Response: RUNNING[2018-04-09 16:51:12.680] [xacc-logger] [info] IBM Accelerator caught exception while calling restClient->get() - Failed to read HTTP status line
[2018-04-09 16:51:12.680] [xacc-logger] [info] Retrying HTTP Get.
Job Response: RUNNINGAssertion failed: (false), function operator[], file /Users/edq/Library/Python/3.6/lib/python/site-packages/xacc-0.1.0-py3.6-macosx-10.11-x86_64.egg/include/rapidjson/include/rapidjson/document.h, line 1103.
Abort trap: 6

EX2:
----> 1 energy = lambda angles: vqe.execute(xaccOp, **{'task':'compute-energy', 'ansatz':IR_fun, 'accelerator':acc, 'vqe-params':str(angles)[1:len(str(angles))-1]
2 })
RuntimeError: Failed to read HTTP status line

OSX compiler installation issues

Automate setting the default compiler to prevent installation issues as per below: CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ python3 setup.py install --user

Add TNQVM as a tpl, a default accelerator

We made TNQVM for the validation of the XACC programming model. We should add it is a TPL or git submodule of XACC, that way users installing just XACC will always have at least one accelerator and compiler (xacc-py) by default.

Add general results dictionary/map to AcceleratorBuffer

Something like AQCAcceleratorBuffer stores D-Wave specific results. We should provide a map<string, Result> to AcceleratorBuffer and a getResults() function so that users can get sub-type-specific results from the AcceleratorBuffer interface-level.

Automatic plugin generation

We need a way to generate a template C++ projects for various xacc extension points. Users can generate these template projects, and fill in pertinent functions to implement what they want. This gets users away from starting up all the boilerplate C++ and CMake code.

Investigate adding new gates at runtime

From @amccaskey on October 12, 2017 21:10

Example - Eugene want's to program shor's algorithm with a modular exponentiation gate instruction that can be hit by a TNQVM visitor.

Copied from original issue: ORNL-QCI/xacc#65

Make ServiceRegistry.initialize Relocatable

This method searches for available xacc plugins and installs them to the cppmicroservices framework.

We need to set this up to not be dependent on the installation directory, as that may not be there in the case of a wheel install.

Currently we search for external plugins in $HOME/.xacc/plugins, and this is fine. But how to load the internal xacc-quantum-{gate,aqc} plugins that are in the installation directory?

My first thought is that we have xacc-framework create a internal $HOME/.xacc/.internal_plugins file that contains the path from

os.path.dirname(os.path.realpath(pyxacc.__file__))

This would require that users run

xacc-framework --initialize 

before using the framework.

ServiceRegistry could start by searching for this .internal_plugins file, and then if not found or invalid, throw an exception that explains to the user that they must run the above initialization command. If found, the plugins are loaded and the the rest of the plugins are loaded.

Now if we start using pip install for plugin wheels, then we must require our users to go through the xacc-framework executable. They would then run

xacc-framework --install tnqvm

which would try to pip install the wheel, and if successful would add the path to the library to the .internal_plugins file. If not successful, then it would be do a custom build and install to .xacc/plugins/

Add a map to ServiceRegistry that keeps track of installed plugins so we don't try to reinstal plugins that have been installed.

Python decorators for XACC kernels

import inspect

class qpu(object):
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
        return
    def __call__(self, f):
        def wrapped_f(*args, **kwargs):
            src = inspect.getsource(f)
            qpu = xacc.getAccelerator(self.kwargs['accelerator'])
            buf = qpu.createBuffer('q')
            program = xacc.Program(qpu, src)
            program.build()
            kernel = program.getKernels()[0]
            kernel.execute(buf, *args)
            return buf
        return wrapped_f

@qpu(accelerator='tnqvm') # or ibm, rigetti, etc...
def foo(theta):
   X(0)
   RY(theta, 1)
   CNOT(1, 0)
   Measure(0,0)
   return

results = foo(np.pi/3.)
print(results.getMeasurementBitStrings())

Accelerator Buffer get measurement samples

From @amccaskey on September 28, 2017 14:48

We need to expose at the AcceleratorBuffer level the ability to return all measurement strings to the user.

Add this to xacc-python as well.

Copied from original issue: ORNL-QCI/xacc#60

Segmentation Fault

Hello,

I have a segmentation fault from getMeasurementStrings and getMeasurementCounts.
I installed XACC and plugings with pip on Docker images.
I am attaching the printing of a simple script and the script.

segfault

import pyxacc as xacc
import sys

def hello(acc="ibm",backendinput="ibmq_qasm_simulator"):
xacc.Initialize(["--compiler","quil"])
accelerator = acc
backend = backendinput

qpu = xacc.getAccelerator(accelerator)
nqbits = 2

xacc.setOption(acc+"-backend",backend)
# code commented is for setting
# the number of trials one run the circuit (default 1024)
# One can set any option that come with the accelerator
# xacc.setOption("ibm-shots","1024")
# xacc.setOption("rigetti-trial","1024")

qreg = qpu.createBuffer("qreg",nqbits)

src = """__qpu__ bell(AcceleratorBuffer b){
H 0
CNOT 0 1
MEASURE 0 [0]
MEASURE 1 [1]
}
"""

program = xacc.Program(qpu,src)
program.build()

k = program.getKernel("bell")
k.execute(qreg,[])

print(qreg.getMeasurementStrings())
print(qreg.getMeasurementCounts())
xacc.Finalize()

if name == "main":

if len(sys.argv) == 3:
    hello(sys.argv[1],sys.argv[2])
else:
    hello()

Implement Kernel Asynchronous execution

From @amccaskey on October 31, 2017 14:57

We should be able to execute kernels both synchronously and asynchronously, where the latter returns futures or promises.

Copied from original issue: ORNL-QCI/xacc#71

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.