Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
imranashraf committed Jul 16, 2018
2 parents 8d66da7 + 10a2c80 commit 2cfe2ac
Show file tree
Hide file tree
Showing 353 changed files with 14,357 additions and 71,613 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
*.o
*.swp
*.swo

*.swn
lab/
bin/
build/
release/
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

SET(PROJECT_NAME "qx-simulator")
PROJECT(${PROJECT_NAME})

FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
ELSE(OPENMP_FOUND)
message("ERROR: OpenMP could not be found.")
ENDIF(OPENMP_FOUND)

IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wfatal-errors -O3 -DCG_BC -DQX_SPARSE_MV_MUL -D__BUILTIN_LINALG__ -msse4.2 -DUSE_OPENMP")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXPU_TIMER")

ADD_SUBDIRECTORY(
src bin
)
2 changes: 1 addition & 1 deletion Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:16.04

RUN apt-get update && \
apt-get -y install g++ autoconf make
apt-get -y install g++ cmake make
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pipeline {
stage('Build') {
steps {
sh 'pwd'
sh 'cd src/ && ./configure && make && make install'
sh 'mkdir build && cd build && cmake ../ && make'
}
}
stage('Test') {
steps {
sh 'cd src/ && ./qx_simulator circuits/epr.qc'
sh 'for file in src/circuits/*.qc; do build/bin/qx-simulator/qx-simulator "$file"; done'

}
}
Expand Down
15 changes: 15 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
To build run the following in the current directory:

mkdir build && cd build && cmake ../ && make

This creates a bin folder containing subfolders:
/bin/qx-server
/bin/qx-simulator
Each containing its respective executable

To install you can further run:
make install
which installs the two executables under the default bin directory, usually:
/usr/local/bin
To change this, cmake can be ran with the following prefix:
cmake -DCMAKE_INSTALL_PREFIX=<desired_absolute_path>
Binary file removed bin/emulator
Binary file not shown.
Binary file removed bin/interface
Binary file not shown.
Binary file removed bin/simulator
Binary file not shown.
Binary file modified doc/Quantum.Code.1.0.User.Manual.pdf
Binary file not shown.
34 changes: 34 additions & 0 deletions qxelarator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# qxelerator: QX as a Quantum Accelerator

This package provides the necessary interface to use QX as an accelerator.

## API

`qxelerator` mainly provides the following 3 API calls:


qx.set('basic.qasm') # set the required qasm to be executed on qx
qx.execute() # execute
res = qx.get_measurement_outcome(0) # get measurement results from qubit 0


## Required packages
At the moment only tested on Linux. Requirements are same as qx plus:
- cmake
- swig
- python development package >= 3.5

## setup

python setup.py install --user

## Usage
See `tests` directory for some simple examples. To run a test, for-example `test_basic.py`, execute

python test_basic.py

## Clean
To clean temporary files generated by install, execute:

make clean

19 changes: 19 additions & 0 deletions qxelarator/cleanme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# script to clean temporary files generated by installation

import os
import shutil

dirs = ['build', 'cbuild', 'dist', 'qxelarator.egg-info']
files = ['qxelarator/qxelarator.py']

for dir in dirs:
try:
shutil.rmtree(dir)
except OSError:
pass

for file in files:
try:
os.remove(file)
except OSError:
pass
5 changes: 5 additions & 0 deletions qxelarator/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# this makefile cleans the tempory files created during the installation
clean:
@-echo "Cleaning temporary files created by install ..."
@-rm -rf build cbuild qxelarator.egg-info dist qxelarator/qxelarator.py qxelarator/_qxelarator.so
@-echo "Done"
38 changes: 38 additions & 0 deletions qxelarator/qxelarator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

SET(PROJECT_NAME "qxelarator")

PROJECT(${PROJECT_NAME})
SET(CMAKE_BUILD_TYPE Release)

FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

FIND_PACKAGE(PythonLibs)

## These are the include directories used by the compiler.
INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../../src
${PROJECT_SOURCE_DIR}/../../src/xpu-0.1.5
${PYTHON_INCLUDE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}
)

FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
ELSE(OPENMP_FOUND)
message("ERROR: OpenMP could not be found.")
ENDIF(OPENMP_FOUND)

IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wfatal-errors -O3 -DCG_BC -DQX_SPARSE_MV_MUL -D__BUILTIN_LINALG__ -msse4.2 -DUSE_OPENMP")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

SET_SOURCE_FILES_PROPERTIES(qxelarator.i PROPERTIES CPLUSPLUS ON)
SET_PROPERTY(SOURCE qxelarator.i PROPERTY SWIG_FLAGS -castmode -modern -keyword)
SWIG_ADD_MODULE(qxelarator python qxelarator.i)
SWIG_LINK_LIBRARIES(qxelarator ${PYTHON_LIBRARIES})
16 changes: 16 additions & 0 deletions qxelarator/qxelarator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Author Imran Ashraf


# The import syntax changes slightly between python 2 and 3, so we
# need to detect which version is being used:
from sys import version_info
if version_info[0] == 3:
PY3 = True
# elif version_info[0] == 2:
# PY3 = False
else:
raise EnvironmentError("sys.version_info refers to a version of "
"Python is not 3. This is not permitted. "
"sys.version_info = {}".format(version_info))

from .qxelarator import QX
174 changes: 174 additions & 0 deletions qxelarator/qxelarator/qx_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/**
* @file qx_interface.h
* @author Nader Khammassi
* @date 20-12-15
* @brief provide a dummy qx interface
* to ease qx code reuse
*/

#ifndef QX_INTERFACE
#define QX_INTERFACE

#include <ql/openql.h>

#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
#include <cstdlib>
#include <map>

#include <stdint.h>

#ifndef println
#define println(x) std::cout << x << std::endl
#endif

/**
* qx wrapper
*/
namespace qx
{
/**
* error_model_t
*/
typedef enum __error_model_t
{
__depolarizing_channel__,
__amplitude_phase_damping__,
__pauli_twirling__,
__unknown_error_model__
} error_model_t;

/**
* gate implementation
*/
#define __define_qx_gate(g) \
class g : public gate \
{ \
public: g(...)\
{}\
};

/**
* gate interface
*/
class gate
{
};

/**
* definitions of supported gates
*/
__define_qx_gate(prepz);
__define_qx_gate(pauli_x);
__define_qx_gate(pauli_y);
__define_qx_gate(pauli_z);
__define_qx_gate(rx);
__define_qx_gate(ry);
__define_qx_gate(rz);
__define_qx_gate(hadamard);
__define_qx_gate(phase);
__define_qx_gate(phase_shift);
__define_qx_gate(t_gate);
__define_qx_gate(t_dag_gate);
__define_qx_gate(cphase);
__define_qx_gate(cnot);
__define_qx_gate(swap);
__define_qx_gate(ctrl_phase_shift);
__define_qx_gate(toffoli);
__define_qx_gate(measure);
__define_qx_gate(display);
__define_qx_gate(prepare);
__define_qx_gate(bin_ctrl);
__define_qx_gate(classical_not);

// gates (availble only on the qx server version)
// to do : implement them on the local qx simulator
__define_qx_gate(qwait);
__define_qx_gate(id);
__define_qx_gate(rx180);
__define_qx_gate(ry180);
__define_qx_gate(rz180);
__define_qx_gate(rx90);
__define_qx_gate(ry90);
__define_qx_gate(rz90);
__define_qx_gate(mrx180);
__define_qx_gate(mry180);
__define_qx_gate(mrz180);
__define_qx_gate(mrx90);
__define_qx_gate(mry90);
__define_qx_gate(mrz90);

/**
* debug instruction
*/
class print_str : public gate
{
public:
print_str(std::string s)
{
}
};

/**
* parallel gates
*/
class parallel_gates : public gate
{
public:

std::vector<gate *> gates;

/**
* parallel gate
*/
parallel_gates()
{
}

/**
* add gate
*/
void add(gate * g)
{
gates.push_back(g);
}
};


/**
* circuit container
*/
class circuit
{
public:

size_t num_qubits;
size_t iterations;
std::string name;
std::vector<gate *> gates;

/**
* circuit
*/
circuit(size_t num_qubits, std::string name="", size_t iterations=1) : num_qubits(num_qubits), iterations(iterations), name(name)
{
}

/**
* add gate circuit
*/
void add(gate * g)
{
gates.push_back(g);
}
};

// types definition

} // namespace qx


#endif // QX_INTERFACE
Loading

0 comments on commit 2cfe2ac

Please sign in to comment.