Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
bf4da19
Minor corrections to custom app functionality
Tognognongo Mar 17, 2025
fb1e02e
Adding generalization of RB app
Tognognongo May 1, 2025
05fd831
WIP
mghibaudi May 22, 2025
c5151bf
Adding tests
mghibaudi May 22, 2025
4db732d
Black
mghibaudi May 22, 2025
c594579
WIP
mghibaudi May 22, 2025
2ade4d3
WIP
mghibaudi May 22, 2025
5898d0b
Merge remote-tracking branch 'origin/main' into togno
Tognognongo Jun 5, 2025
8e00bb6
Merge remote-tracking branch 'origin/app_args' into togno
Tognognongo Jun 11, 2025
472972c
Improving argument passing
mghibaudi Jun 20, 2025
ad9b9d8
Black
mghibaudi Jun 20, 2025
c29f50d
cleanup
mghibaudi Jun 20, 2025
de1bb6d
cleanup test
mghibaudi Jun 20, 2025
f44ed3e
Dropping support for Python3.9
mghibaudi Jun 20, 2025
4d04f15
Dropping support for Python3.9
mghibaudi Jun 20, 2025
e1c791c
Updating pygsti version
mghibaudi Jun 20, 2025
d8eae11
Pandera
mghibaudi Jun 20, 2025
d26479f
Adding check for empty string
mghibaudi Jun 20, 2025
2e0b833
Updating lock file
mghibaudi Jun 20, 2025
2ea02df
Merge branch 'main' of github.com:riverlane/QStone into app_args
mghibaudi Jun 20, 2025
fd7fd6a
poetry lock
mghibaudi Jun 20, 2025
f929444
Update security.yaml
mghibaudi Jul 1, 2025
3d2bb7d
Minor changes to RB app
Tognognongo Jul 3, 2025
68d98f2
Fixing merge issues
Tognognongo Jul 3, 2025
015e76c
Cleaned RB app
Tognognongo Aug 20, 2025
b5dfe8f
Solved merge conflicts
Tognognongo Aug 20, 2025
c9fb4ed
Added logging level to QBC and RB apps
Tognognongo Aug 20, 2025
1ee341d
Minor changes to QBC
Tognognongo Aug 20, 2025
482e847
Fixed bug with atomic run
Tognognongo Sep 18, 2025
1afd9c0
Reformatted files
Tognognongo Sep 18, 2025
bb57960
Changed imports in RB.py
Tognognongo Sep 18, 2025
ac566af
Changed import sorting in RB.py
Tognognongo Sep 18, 2025
c501277
Added poetry.lock
Tognognongo Sep 18, 2025
fb897b2
Fixed RB.py init
Tognognongo Sep 18, 2025
12bda3e
Reformatted files
Tognognongo Sep 18, 2025
9cb96a2
Fixed app_args definition
Tognognongo Sep 18, 2025
d92dd91
Fixed app_args definition again
Tognognongo Sep 18, 2025
19c94c7
Added nompi implementation of mpi_communication function
Tognognongo Sep 18, 2025
54bf85b
Fixed bug in nompi.py
Tognognongo Sep 18, 2025
09fa400
Fixed to QBC.py
Tognognongo Sep 18, 2025
0fac903
Fixing apps bugs
Tognognongo Sep 18, 2025
680e773
Fixed typo in import line
Tognognongo Sep 18, 2025
b95e6cd
Fix bug
Tognognongo Sep 18, 2025
9cc6b8a
Resorted imports
Tognognongo Sep 18, 2025
0cb41b4
Added changes to app_args
Tognognongo Sep 18, 2025
2bbccf6
Fix bug
Tognognongo Sep 18, 2025
d4960c3
Fixed bug with number of RBs
Tognognongo Sep 18, 2025
b2f35fe
Added description of function in utils.py
Tognognongo Sep 18, 2025
b8163de
Removed asserting fixed number of circuits and shots for the RB app
Tognognongo Sep 18, 2025
d2d6327
Addressing Pylint warning
Tognognongo Sep 18, 2025
e786f92
Fixing Pylint issue
Tognognongo Sep 18, 2025
a66b227
Fixing issue with exp array size
Tognognongo Sep 19, 2025
6d7dccb
Made string indexes in RB integers
Tognognongo Sep 19, 2025
28d50bf
Fixed test issue reading expected RB states
Tognognongo Sep 22, 2025
ad873b6
Forced the counts dictionary keys to be strings
Tognognongo Sep 22, 2025
22b1dd2
Changed RB_run_test.npz to match new app results format
Tognognongo Sep 23, 2025
093380a
Reformatted RB.py
Tognognongo Sep 23, 2025
c7c4bf4
Addressing Copilot suggestions and adding application arguments for t…
Tognognongo Oct 2, 2025
a3ff7e3
Fixed bug in the loss function definition
Tognognongo Oct 2, 2025
06ebe12
Fixing black and isort failed checks
Tognognongo Oct 2, 2025
6bb504c
Reformatted RB.py file
Tognognongo Oct 2, 2025
927f3f8
Update security.yaml
mghibaudi Oct 3, 2025
d236de2
Update security.yaml
mghibaudi Oct 3, 2025
902b99e
Update tox.ini
mghibaudi Oct 3, 2025
f40e278
Update qstone/apps/RB.py
mghibaudi Oct 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ Create a `config.json` file with the following structure:
]
}
```
### Additional arguments

Additional arguments can be passed to quantum applications in the "jobs" array though `app_args' objects:

```
{ "type": "RB",
"app_args": {
"benchmarks": list of lists, each containing the qubit numbers on which one- or two-qubit RBs will be run, # [[0],[1,2]]
"depths": list of integers representing the different number of Clifford gates employed in the RB, # [2,4,8,16]
"reps": integer representing the number of times circuits of a particular depth are generated, # 10
}
}

{ "type": "QBC",
"app_args": {
"pqc_number" : integer in [2,5,15] representing the parametrized quantum circuit with the same number
in figure 2 of Adv. Quantum Technol. 2, 1900070 (2019)
"training_size" : integer representing the number of feature vectors in the training dataset # 20
"max_iters" : integer representing the maximum number of iterations in the model's training
}
}
```


For detailed configuration options, refer to the [JSON schema](qstone/utils/config_schema.py).

Expand Down
3,554 changes: 1,960 additions & 1,594 deletions poetry.lock

Large diffs are not rendered by default.

49 changes: 38 additions & 11 deletions qstone/apps/QBC.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""QBC computations steps."""

import base64
import os
import pickle
import sys

import numpy
from pandera import Check, Column, DataFrameSchema
Expand All @@ -12,10 +15,15 @@
from qstone.utils.utils import ComputationStep, trace


def _to_ob(string):
return pickle.loads(base64.b64decode(string.encode("utf-8")))
Comment thread
mghibaudi marked this conversation as resolved.


@trace(
computation_type="QBC",
computation_step=ComputationStep.RUN,
label="QASM_GENERATION",
logging_level=4,
)
def generate_vqc_qasm(pqc_number, num_qubits, datum, parameters):
"""
Expand Down Expand Up @@ -80,6 +88,7 @@ def generate_vqc_qasm(pqc_number, num_qubits, datum, parameters):
computation_type="QBC",
computation_step=ComputationStep.RUN,
label="MPI_COMMUNICATION",
logging_level=4,
)
def mpi_communication(data, comm, bcast=True):
"""MPI communication wrapper"""
Expand All @@ -90,6 +99,7 @@ def mpi_communication(data, comm, bcast=True):
computation_type="QBC",
computation_step=ComputationStep.RUN,
label="LOSS_COMPUTATION",
logging_level=3,
)
def loss(
parameters,
Expand Down Expand Up @@ -124,16 +134,15 @@ def loss(
counts = response["counts"]
else:
print("ERROR: counts not found in qpu response.")
quit()
counts = response
sys.exit()
probs = {key: counts[key] / shots for key in counts.keys()}
loss -= probs[str(labels[i])] / training_size
if str(labels[i]) in probs.keys():
loss -= probs[str(labels[i])] / training_size
print(f"partial loss for rank {comm.Get_rank()}: {loss}", flush=True)
temp = mpi_communication(loss, comm, bcast=False)
loss = temp
print(f"total loss: {loss}", flush=True)
total_loss = mpi_communication(loss, comm, bcast=False)
print(f"total loss: {total_loss}", flush=True)

return loss
return total_loss


class QBC(Computation): # pylint:disable=invalid-name
Expand Down Expand Up @@ -179,6 +188,25 @@ def __init__(self, cfg: dict):
self.size = self.comm.Get_size()
self.rank = self.comm.Get_rank()

self.num_required_qubits = int(
os.environ.get("NUM_QUBITS", cfg.get("num_required_qubits", 4))
)
self.shots = int(os.environ.get("NUM_SHOTS", str(cfg.get("shots", 64))))
app_args: dict = {}
env_app_args = os.environ.get("APP_ARGS", "")
if env_app_args != "":
loaded = _to_ob(env_app_args)
if isinstance(loaded, dict):
app_args = loaded
else:
pass
if "pqc_number" in app_args.keys():
self.pqc_number = int(app_args["pqc_number"])
if "training_size" in app_args.keys():
self.benchmarks = int(app_args["training_size"])
if "max_iters" in app_args.keys():
self.depths = int(app_args["max_iters"])
Comment thread
mghibaudi marked this conversation as resolved.

@trace(
computation_type=COMPUTATION_NAME,
computation_step=ComputationStep.PRE,
Expand Down Expand Up @@ -225,21 +253,20 @@ def run(self, datapath: str, connection: connector.Connector):
starts = list(sum(jobsizes[:i]) for i in range(len(jobsizes)))
idxs = numpy.arange(starts[self.rank], starts[self.rank] + jobsizes[self.rank])

totqasms: list = []
totresults: list = []
totlosses: list = []
if self.pqc_number in [2, 15]:
totparameters = (
2 * numpy.pi * numpy.random.rand(2 * self.num_required_qubits)
)
if self.pqc_number == 5:
elif self.pqc_number == 5:
totparameters = (
2
* numpy.pi
* numpy.random.rand(
pow(self.num_required_qubits, 2) + 3 * self.num_required_qubits
)
)
else:
raise ValueError(f"Unknown pqc_number: {self.pqc_number}")

mpi_communication(totparameters, self.comm)

Expand Down
Loading