Skip to content

Commit 3958a1f

Browse files
committed
Merge remote-tracking branch 'upstream/development' into ncu
2 parents 040f029 + 2156494 commit 3958a1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4984
-886
lines changed

.github/workflows/docker-image.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master, development ]
8+
9+
jobs:
10+
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Build the Docker image
18+
run: docker build -t intel-qs:$(date +%s) .

.github/workflows/python_build_mp.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

Dockerfile

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@
1717
# Use an official Ubuntu linux image as the run time environment.
1818
FROM ubuntu:latest
1919

20-
# Setup the proxy server environment.
21-
ENV http_proxy http://proxy-chain.intel.com:911
22-
ENV https_proxy http://proxy-chain.intel.com:911
23-
2420
# Fetch and install the GNU Make utility.
2521
RUN apt-get update && apt-get install -y build-essential g++ make
2622

2723
# Fetch and install a generic MPI implementation.
28-
RUN apt-get update && apt-get install -y mpich
24+
RUN apt-get update && DEBIAN_FRONTEND=nonitneractive apt-get install -y mpich
2925

3026
# Fetch and install OpenSSH (client/server) for interacting between
3127
# nodes of the cluster in a Docker swarm configuration.
@@ -62,22 +58,28 @@ RUN apt-get update && \
6258
apt-get upgrade -y && \
6359
apt-get install -y git
6460

65-
# Install VIM to edit files.
66-
RUN apt-get install -y vim
6761

6862
# Setup the local build environment for the simulation framework.
6963
WORKDIR /root/intelqs
7064
COPY . /root/intelqs
7165

7266
#FIXME
7367
# For stability reasons, the container should not be used as 'root'.
74-
# A new user is created, named 'tester':
75-
#RUN useradd --home-dir /home/tester --create-home tester
76-
#WORKDIR /home/tester/intelqs
77-
#COPY . /home/tester/intelqs
68+
# A new user is created, named 'user':
69+
#RUN useradd --home-dir /home/user --create-home user
70+
#WORKDIR /home/user/intelqs
71+
#COPY . /home/user/intelqs
7872

79-
#FIXME
80-
# Install Intel Quantum Simulator
81-
#RUN source /opt/intel/mkl/bin/mklvars.sh intel64 ilp64
82-
#RUN mkdir build; cd build; CXX=g++ cmake -DIqsMPI=OFF -DIqsUtest=ON -DIqsPython=OFF ..
73+
# install lib for missing pthread module
74+
RUN apt-get -y install libboost-all-dev
8375

76+
# installing and configuring conda env
77+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
78+
RUN bash ~/miniconda.sh -b -p $HOME/miniconda
79+
ENV PATH="/root/miniconda/bin:$PATH"
80+
RUN /bin/bash -c ". ~/.bashrc && \
81+
conda install -y notebook && \
82+
conda install -y pybind11 && \
83+
conda install -y numpy && \
84+
conda install -y matplotlib"
85+
# Dockerfile Ends here

README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
![C++ build with CMake](https://github.com/iqusoft/intel-qs/workflows/C++%20build%20with%20CMake/badge.svg)
2-
![Python build (no MPI)](https://github.com/iqusoft/intel-qs/workflows/Python%20build%20(no%20MPI)/badge.svg?branch=develop-action)
3-
![Python build with MPI](https://github.com/iqusoft/intel-qs/workflows/Python%20build%20with%20MPI/badge.svg?branch=develop-action)[![arXiv](https://img.shields.io/static/v1?label=arXiv&message=2001.10554&color=success)](https://arxiv.org/abs/2001.10554)
2+
![Python build (no MPI)](https://github.com/iqusoft/intel-qs/workflows/Python%20build%20(no%20MPI)/badge.svg)
3+
[![Published Dockerfile](https://img.shields.io/badge/docker%20build-passing-181717?style=flat-square&logo=github&labelColor=black&color=brightgreen)](https://github.com/iqusoft/intel-qs/blob/development/Dockerfile)
4+
[![arXiv](https://img.shields.io/static/v1?label=arXiv&message=2001.10554&color=success)](https://arxiv.org/abs/2001.10554)
45
[![arXiv](https://img.shields.io/static/v1?label=arXiv&message=1601.07195&color=inactive)](https://arxiv.org/abs/1601.07195)
56

67
# Intel Quantum Simulator
@@ -101,16 +102,15 @@ Underneath, this option uses [`-xhost`](https://software.intel.com/en-us/cpp-com
101102
with Intel compilers and [`-march=native`](https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html) with GNU compilers.
102103

103104

104-
### Enable Python binding
105+
### Enable Python binding (only available without MPI)
105106

106-
By default, the compilation does not include the the Python binding for
107+
By default, whenever MPI is disabled, the building process includes the Python binding for
107108
Intel-QS. The binding code uses the Pybind11 library which needs to be installed via 'conda'
108109
(and not simply with pip) to include the relevant information in CMake.
109110
See [this page](https://github.com/pybind/pybind11/issues/1628) for more info on this issue.
110111

111-
To enable the Python wrap set the CMake option selection to
112-
`-DIqsPython=ON`.
113-
This option works also with the MPI buile enabled.
112+
To disable the Python wrap, even without MPI, set the CMake option selection to
113+
`-DIqsPython=OFF`.
114114

115115

116116
### Unit test
@@ -144,18 +144,49 @@ A quick look at the options can be found at
144144
`Dockerfile` includes the instructions to build the docker image of an Ubuntu machine
145145
with Intel-QS already installed. The image can be 'run' to create a container.
146146
The container can be 'executed' to login into the machine.
147+
For this, Three steps need to be followed to prepare containerirzed intelqs simulator.
148+
149+
* Create container
150+
* Configure SSH tunneling
151+
* Launch Jupyter notebook
152+
153+
#### Create container
154+
155+
Important: If user is not `root`,add `sudo` before each bash and docker command.
156+
First command in below will build docker image for Intelqs named qhipster.One can choose other name too.
157+
(if choosen name is other than qhipster, replace that name in all other commands as well).
158+
Second command will create container while mapping 8080 port to the localhost.
159+
Third command will enable conda env,execute cmake and make command, it will launch jupyter notebook
160+
in the terminal. Copy and save the printed token from the terminal.
161+
`Example of a given token : http://127.0.0.1:8080/?token=6ee42173ee71353c1f1b33f8feb33132aed15f2a07960bc8`.
162+
Last command is optional,this can be executed to go inside container.
147163

148164
```bash
149165
docker build -t qhipster .
150-
docker run -d -t qhipster
151-
docker ps
152-
docker exec -itd <container_id> /bin/bash
166+
docker run -d -t -p 8080:8080 qhipster
167+
docker exec -i $(docker ps|grep -i qhipster|cut -d ' ' -f1) /bin/bash -c ". ~/.bashrc && . /opt/intel/mkl/bin/mklvars.sh intel64 ilp64 && . /opt/intel/bin/compilervars.sh -arch intel64 -platform linux && mkdir build && cd build && CXX=g++ cmake -DIqsMPI=OFF -DIqsUtest=ON -DIqsPython=ON .. && make && cd .. && jupyter notebook --ip 0.0.0.0 --port 8080 --no-browser --allow-root"
168+
docker exec -it $(docker ps|grep -i qhipster|cut -d ' ' -f1) /bin/bash
153169
```
154170

155171
If Docker is used on a Windows host machine, the last line should be substituted by:
156-
`winpty docker exec -itd <container_id> //bin/bash`.
172+
`winpty docker exec -it <container_id> //bin/bash`.
157173

158174

175+
#### Configure SSH tunneling
176+
177+
In local laptop, open Ubuntu emulator. This to allow the use of SSH protocol for port forwarding.
178+
For example if you use MobaxTerm tool,launch a session and type following command in the mobxterm shell:
179+
180+
```bash
181+
ssh -L 8080:localhost:8080 user@domain.com
182+
```
183+
184+
#### Launch Jupyter notebook
185+
186+
Now, paste the copied token(which we copied from 'Create Container' section) in your preffered web browser
187+
(most importantly, please clear your browser cache before pasting the token). Once you are seeing all
188+
folders and files in browser, follow below section to begin.
189+
159190
----
160191
## Getting started with Intel-QS
161192

@@ -168,7 +199,6 @@ define a qubit register object, perform quantum gates, measure one or multiple q
168199
If the Python bindings were enabled, the same learning can be performed using the iPython
169200
notebook `tutorials/get_started_with_IQS.ipynb`.
170201

171-
172202
----
173203
## How to contribute
174204

benchmarks/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
add_executable(basic_code_for_scaling.exe basic_code_for_scaling.cpp)
2+
add_executable(specv2_bench.exe specv2_bench.cpp)
23
target_link_libraries(basic_code_for_scaling.exe PRIVATE iqs)
4+
target_link_libraries(specv2_bench.exe PRIVATE iqs)
35

4-
set_target_properties( basic_code_for_scaling.exe
6+
set_target_properties(
7+
basic_code_for_scaling.exe
8+
specv2_bench.exe
59
PROPERTIES
610
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin"
711
)
8-
9-

benchmarks/specv2_bench.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
Comparison of Runtime Performance of TurnOnSpecialize and TurnOnSpecializeV2.
3+
A single node system with one or more threads is assumed.
4+
Thread count should be set by using export OMP_NUM_THREADS=<thread_count>.
5+
*/
6+
// TODO: Add documentation
7+
8+
#include <array>
9+
#include <chrono>
10+
#include <vector>
11+
#include "../include/qureg.hpp"
12+
13+
template <typename Function>
14+
void benchmark(const std::vector<std::array<int, 2>> &pairs, const char *name, Function func)
15+
{
16+
//See https://stackoverflow.com/questions/11062804/measuring-the-runtime-of-a-c-code
17+
auto start = std::chrono::steady_clock::now();
18+
for (const auto &p : pairs)
19+
func(p[0], p[1]);
20+
auto end = std::chrono::steady_clock::now();
21+
auto elapsed = std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
22+
std::cout << name << ": " << elapsed.count() << " seconds\n";
23+
}
24+
25+
int main(int argc, char *argv[])
26+
{
27+
qhipster::mpi::Environment::Init(argc, argv);
28+
29+
if (argc != 2 && argc != 3)
30+
{
31+
std::cout << "Usage: " << argv[0] << " <num_qubits> [<do_comparison> = 0]\n";
32+
return 0;
33+
}
34+
35+
int nbits = atoi(argv[1]);
36+
std::cout << "Num Qubits: " << nbits << "\n";
37+
38+
bool compare_states = false;
39+
if (argc == 3)
40+
compare_states = static_cast<bool>(atoi(argv[2]));
41+
42+
if (compare_states) // Compare only for small numbers
43+
std::cout << "State comparison will be performed" << std::endl;
44+
else
45+
std::cout << "State comparison will not be performed" << std::endl;
46+
47+
// Comparison variables
48+
QubitRegister<ComplexDP>* psi0 = nullptr;
49+
const double tol = 1e-9;
50+
51+
std::vector<std::array<int, 2>> pairs;
52+
for (int i = 0; i < nbits; ++i)
53+
pairs.push_back({i, (i + 1) % nbits});
54+
55+
for (int i = 0; i < 3; ++i)
56+
{
57+
QubitRegister<ComplexDP> psi(nbits, "base", 0);
58+
if (i == 1)
59+
{
60+
psi.TurnOnSpecialize();
61+
std::cout << "\nBenchmarking with spec v1\n------------\n";
62+
}
63+
else if (i == 2)
64+
{
65+
std::cout << "\nBenchmarking with spec v2\n------------\n";
66+
psi.TurnOnSpecializeV2();
67+
}
68+
else
69+
{
70+
std::cout << "\nBenchmarking without spec\n------------\n";
71+
}
72+
// More gates can be added in the similar fashion
73+
// Covers all spec2 gates as of August 21, 2020
74+
benchmark(pairs, "H ", [&psi](int i, int j) { psi.ApplyHadamard(i); });
75+
benchmark(pairs, "T ", [&psi](int i, int j) { psi.ApplyT(i); });
76+
benchmark(pairs, "RX ", [&psi](int i, int j) { psi.ApplyRotationX(i, M_PI / 3); });
77+
benchmark(pairs, "RY ", [&psi](int i, int j) { psi.ApplyRotationY(i, M_PI / 6); });
78+
benchmark(pairs, "RZ ", [&psi](int i, int j) { psi.ApplyRotationZ(i, M_PI / 4); });
79+
benchmark(pairs, "X ", [&psi](int i, int j) { psi.ApplyPauliX(i); });
80+
benchmark(pairs, "Y ", [&psi](int i, int j) { psi.ApplyPauliY(i); });
81+
benchmark(pairs, "Z ", [&psi](int i, int j) { psi.ApplyPauliZ(i); });
82+
83+
benchmark(pairs, "CH ", [&psi](int i, int j) { psi.ApplyCHadamard(i, j); });
84+
benchmark(pairs, "CRX", [&psi](int i, int j) { psi.ApplyCRotationX(i, j, M_PI / 3); });
85+
benchmark(pairs, "CRY", [&psi](int i, int j) { psi.ApplyCRotationY(i, j, M_PI / 6); });
86+
benchmark(pairs, "CRZ", [&psi](int i, int j) { psi.ApplyCRotationZ(i, j, M_PI / 4); });
87+
benchmark(pairs, "CX ", [&psi](int i, int j) { psi.ApplyCPauliX(i, j); });
88+
benchmark(pairs, "CY ", [&psi](int i, int j) { psi.ApplyCPauliY(i, j); });
89+
benchmark(pairs, "CZ ", [&psi](int i, int j) { psi.ApplyCPauliZ(i, j); });
90+
benchmark(pairs, "CPh", [&psi](int i, int j) { psi.ApplyCPhaseRotation(i, j, M_PI / 4); });
91+
92+
if (compare_states)
93+
{
94+
if (i == 0)
95+
{
96+
psi0 = new QubitRegister<ComplexDP>(psi);
97+
continue;
98+
}
99+
100+
auto diff = psi0->MaxAbsDiff(psi, {1, 0});
101+
if (diff < tol)
102+
{
103+
std::cout << "State comparison test passed for spec " << i << std::endl;
104+
}
105+
else
106+
{
107+
std::cerr << "State comparison test failed for spec " << i
108+
<< "\nMax diff: " << diff << "\nAborting..." << std::endl;
109+
break;
110+
}
111+
}
112+
}
113+
114+
if (compare_states)
115+
delete psi0;
116+
117+
qhipster::mpi::Environment::Finalize();
118+
119+
return 0;
120+
}

examples/grover_4qubit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
// Include the header file including the declaration of the QbitRegister class
1919
// and of its methods.
20-
#include "../qureg/qureg.hpp"
21-
#include "../qureg/permute.hpp"
20+
#include "../include/qureg.hpp"
21+
#include "../include/permute.hpp"
2222

2323
// Start of the main program (C++ language).
2424
int main(int argc, char **argv)

examples/quantum_fourier_transform.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ void qft(QubitRegister<Type> &psi)
3232
int n = qhipster::ilog2(psi.size());
3333

3434
// main computation
35+
//
36+
// 6 -H----*------*--------*--...--------------*----x------ 6
37+
// 5 ----H-R----*-|------*-|--...------------*-|----|-x---- 5
38+
// 4 ---------H-R-R----*-|-|--...----------*-|-|----|-|-x-- 4
39+
// 3 ----------------H-R-R-R--...--------*-|-|-|----|-|-|-- 3
40+
// 2 -------------------------...------*-|-|-|-|----|-|-x-- 2
41+
// 1 -------------------------...----*-|-|-|-|-|----|-x---- 1
42+
// 0 -------------------------...--H-R-R-R-R-R-R----x------ 0
43+
//
3544
for (int i = n - 1; i >= 0; i--)
3645
{
3746
for (int j = n - 1; j > i; j--)

0 commit comments

Comments
 (0)