Skip to content

Commit 2b45cd9

Browse files
Merge pull request #3 from TNO-Quantum/quandela
Add quandela solver
2 parents 2f35be8 + 78f6453 commit 2b45cd9

File tree

9 files changed

+370
-36
lines changed

9 files changed

+370
-36
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175

176176
END OF TERMS AND CONDITIONS
177177

178-
Copyright 2023 The Netherlands Organisation for Applied Scientific Research (TNO)
178+
Copyright 2024 The Netherlands Organisation for Applied Scientific Research (TNO)
179179

180180
Licensed under the Apache License, Version 2.0 (the "License");
181181
you may not use this file except in compliance with the License.

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
This repository contains python code to run the Q-score (Max-Cut and Max-Clique) benchmark on the following solver backends:
66

7-
- D-Wave devices and solvers, precisely its `Advantage_system4.1` and `DW_2000Q_6` QPU solvers, its `Simulated Annealing` and `qbsolv` classical solver, and its `hybrid` solver.
7+
- D-Wave QPU device, the `Advantage_system4.1` ~~and `DW_2000Q_6`~~ QPU system. (The `DW_2000Q_6` device no longer available.)
8+
- D-Wave classical solvers, its `Simulated Annealing` and `qbsolv` solver
9+
- D-Wave hybrid solver.
810
- Gate-based hardware using QAOA on QuantumInspire and IBM hardware or simulators.
9-
- Simulator for Gaussian Boson Sampling, a form of photonic quantum computing.
11+
- Gaussian Boson Sampling, a form of photonic quantum computing, both simulated an using the 12-mode Quandela QPU.
1012

1113
For an introduction to the Q-score, see the reference below.
12-
Q-score instances for Max-Cut or Max-Clique optimization problem can be run for different sizes and timeout limits. If no result is found within the allowed time limit, no objective result and a beta value of `0` is returned. Note that for the QPU solvers, the time limit considers embedding time only. The actual computation time will be slightly higher, but this difference will be in the order of milliseconds and will hence not influence the results. For similar reasons, for the photonic simulator, we only apply the time constraint to the classical runtime of the algorithm. To compute the Q-score, one runs for increasing graph size sufficiently many instances of the given code to check whether the average beta is larger than 0.2.
14+
Q-score instances for Max-Cut or Max-Clique optimization problem can be run for different sizes and timeout limits. If no result is found within the allowed time limit, no objective result and a beta value of `0` is returned. Note that for the QPU solvers, the time limit considers embedding time only. The actual computation time will be slightly higher, but this difference will be in the order of milliseconds and will hence not influence the results. For similar reasons, for the photonic simulator, we only apply the time constraint to the classical runtime of the algorithm. To compute the Q-score, one runs for increasing graph size sufficiently many instances of the given code to check whether the average beta is larger than `0.2`.
1315

1416
This code was used to obtain results for the following papers:
1517

1618
- ["Evaluating the Q-score of quantum annealers", Ward van der Schoot et al. (IEEE QSW 2022)](https://ieeexplore.ieee.org/document/9860191).
17-
- ["Q-score Max-Clique: The first metric evaluation on multiple computational paradigms", Ward van der Schoot et al. (preprint)](https://arxiv.org/abs/2302.00639)
19+
- ["Q-score Max-Clique: The first metric evaluation on multiple computational paradigms", Ward van der Schoot et al. (2023 arXiv)](https://arxiv.org/abs/2302.00639)
1820

1921
## Q-score introduction
2022

@@ -63,7 +65,7 @@ Multiple Q-score instances for various sizes can be run as follows:
6365

6466
To use this code we assume that the reader has installed the requirements and set up access to the required solvers.
6567

66-
Requirements can be installed using pip:
68+
Requirements can be installed using pip and have been tested for `python3.9` and `python3.10`:
6769
```terminal
6870
python -m pip install -r requirements.txt
6971
```
@@ -108,3 +110,13 @@ Example usage for the IBM Lima device:
108110
```python
109111
python evaluate.py -p "max-clique" -s 5 -t 60 -n 1024 -solver "QAOA" -provider "ibm" -backend "ibmq_lima"
110112
```
113+
114+
### Set up Quandela configuration
115+
116+
To use the Quandela hardware backend, one need to create and Quandela Cloud account, which can be done [here](https://cloud.quandela.com/webide/login).
117+
After creating your account you can store your API key inside the `configuration/_QUANDELA_API_KEY`:
118+
119+
Example usage for the photonic Quandela Ascella hardware:
120+
```python
121+
python evaluate.py -p "max-clique" -s 3 -t 60 -n 1024 -solver "Photonic_quandela" -backend "qpu:ascella"
122+
```

calculate_qscore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def calculate_qscore(
7070
for size in size_range:
7171
result, times = [], []
7272
exact_results = []
73-
for _ in range(nb_instances_per_size):
73+
for i in range(nb_instances_per_size):
74+
print(f"START INSTANCE {i}")
7475
objective_result, _, time, G = main(
7576
problem_type=problem_type,
7677
size=size,

evaluate.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from run.run_dwave_qpu import run_dwave_qpu
1414
from run.run_hybrid import run_hybrid
1515
from run.run_photonic_simulated import run_photonic_simulated
16+
from run.run_photonic_quandela import run_photonic_quandela
1617
from run.run_QAOA import run_QAOA
1718
from run.run_qbsolv import run_qbsolv
1819
from run.run_SA import run_SA
@@ -69,7 +70,7 @@ def parse_args() -> argparse.Namespace:
6970
parser.add_argument(
7071
"-provider",
7172
"--provider",
72-
help="Name of hardware provider in case QAOA is selected.",
73+
help="Name of hardware provider in case `QAOA` is selected.",
7374
choices=[
7475
"local simulator",
7576
"ibm",
@@ -81,7 +82,7 @@ def parse_args() -> argparse.Namespace:
8182
parser.add_argument(
8283
"-backend",
8384
"--backend",
84-
help="Name of backend in case QAOA is selected.",
85+
help="Name of backend in case `QAOA` or `Photonic_quandela` is selected.",
8586
type=str,
8687
required=False,
8788
)
@@ -91,11 +92,11 @@ def parse_args() -> argparse.Namespace:
9192
help="String of the D-Wave solver.",
9293
choices=[
9394
"Advantage_system4.1",
94-
"DW_2000Q_6",
9595
"hybrid",
9696
"qbsolv",
9797
"Simulated_Annealing",
9898
"Photonic_Simulation",
99+
"Photonic_quandela",
99100
"QAOA",
100101
],
101102
type=str,
@@ -127,7 +128,7 @@ def main(
127128
seed: random seed for reproducibility.
128129
num_reads: Number of reads/samples in case of a QPU or Simulated Annealing solver.
129130
provider: Name of hardware provider in case QAOA is selected.
130-
backend: Name of backend in case QAOA is selected.
131+
backend: Name of backend in case QAOA or photonic is selected.
131132
132133
Returns:
133134
objective_result: solution to max-cut or max-clique.
@@ -142,16 +143,15 @@ def main(
142143
"""
143144
if num_reads is None and solver in [
144145
"Advantage_system4.1",
145-
"DW_2000Q_6",
146146
"Simulated_Annealing",
147147
"Photonic_Simulation",
148+
"Photonic_quandela",
148149
]:
149150
raise ValueError("num_reads has not been submitted while required by solver.")
150151

151152
if seed is None:
152153
seed = np.random.randint(100000)
153154
G = nx.erdos_renyi_graph(size, 1 / 2, seed=seed)
154-
155155
if solver == "QAOA":
156156
if problem_type == "max-cut":
157157
max_cut = Maxcut(G)
@@ -163,14 +163,20 @@ def main(
163163
start_time = time.time()
164164
objective_result = run_QAOA(qp, provider, backend)
165165
end_time = time.time()
166-
elif solver == "Photonic_Simulation":
166+
elif solver in ["Photonic_Simulation", "Photonic_quandela"]:
167167
if problem_type != "max-clique":
168168
raise ValueError(
169-
"Photonic simulation solver can only be used for Max-Clique problem."
169+
"Photonic solvers can only be used for Max-Clique problems."
170+
)
171+
172+
if solver == "Photonic_Simulation":
173+
objective_result, end_time, start_time = run_photonic_simulated(
174+
G, size=size, n_samples=num_reads, timeout=timeout
175+
)
176+
elif solver == "Photonic_quandela":
177+
objective_result, end_time, start_time = run_photonic_quandela(
178+
G, size=size, backend=backend, n_samples=num_reads, timeout=timeout
170179
)
171-
objective_result, end_time, start_time = run_photonic_simulated(
172-
G, size=size, n_samples=num_reads, timeout=timeout
173-
)
174180
else:
175181
# Create qubo:
176182
if problem_type == "max-cut":
@@ -183,7 +189,7 @@ def main(
183189
)
184190

185191
# Solve problem instance
186-
if solver in ["Advantage_system4.1", "DW_2000Q_6"]:
192+
if solver == "Advantage_system4.1":
187193
start_time = time.time()
188194
objective_result = run_dwave_qpu(Q, size, solver, num_reads, timeout)
189195
end_time = time.time()

requirements.txt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1+
# generic dependencies
12
numpy==1.22.1
23
networkx==2.8.8
4+
matplotlib==3.5.2
5+
6+
# d-wave dependencies
7+
dwave-cloud-client==0.9.3
8+
dwave-greedy==0.2.2
9+
dwave-hybrid==0.6.5
10+
dwave-inspector==0.2.9
11+
dwave-neal==0.5.9
12+
dwave-networkx==0.8.11
313
dwave-ocean-sdk==4.4.0
14+
dwave-preprocessing==0.3.2
15+
dwave-qbsolv==0.3.4
16+
dwave-system==1.12.0
17+
dwave-tabu==0.4.3
18+
dwavebinarycsp==0.1.4
19+
pydantic==1.10.4
20+
21+
# photonic dependencies
422
strawberryfields==0.23.0
5-
matplotlib==3.5.2
6-
qiskit[optimization]==0.39.4
7-
quantuminspire==2.0.0
23+
perceval-quandela==0.8.1
824
python-dotenv==0.21.0
25+
26+
# qaoa dependencies
27+
qiskit[optimization]==0.39.4
28+
quantuminspire==2.2.1
29+
30+
# testing dependencies
931
pytest==7.2.1

0 commit comments

Comments
 (0)