Skip to content

Commit 307989a

Browse files
author
Axel Dahlberg
authored
Merge pull request #38 from SoftwareQuTech/Develop
Release 3.0.3
2 parents dc8c4b3 + 1bb7ec7 commit 307989a

File tree

13 files changed

+77
-24
lines changed

13 files changed

+77
-24
lines changed

.bumpversion.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[bumpversion]
2+
current_version = 3.0.3
3+
commit = True
4+
tag = False
5+
6+
[bumpversion:file:cqc/__init__.py]
7+
[bumpversion:file:README.md]
8+

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ deploy:
2828
user: adahlberg
2929
password:
3030
secure: cQUlOGHX5ksULLBM2kOE9s2hdaJn4WK8rhD4LUuWndUG7rLeqtVfEMVrqWuMmzWcHXKOti143vgthSgp+akixfnQD7jWupVVSRiz5SFgq+1DRezGlkvYcZz2833on28lNFRiTjuPHkY3WoK0sS1iESxwTBvvi4y+q+AGtFzKE8hr+Pej+HnqFMMeXfqE7d/ZhoOrcBiRRcOrV/2JjpET5CMqimCYR4rz25yzpvVWlakC24vCqGs0Py+JL+VlZszjQz25NAQuuVwOAKnH/bapCV/JFmpvrFF5gKqAly9d1/+ZVgQVT9swMPjwmQs3zQ9E7IlL+4BPhdDly1H/GchyTRvf3uFt6Lok8ySvDyIkZUM2HlIoJIJCAESRCoEK7K7t1ySovBKjXI1Jc8O3QhAvdVMFWPpVxq5ZKwvUAEKtt7vRzN2KVmSi1nJxEzL89iuZkUtihws6DD8Y/6VgcemCFEZlP8ubxxRqR6gSaAhxSHppTdlNK2xUKq5AOwuS8A/3ur7SsMGasmMXTgQ/ElkrlHSZDvub4A89EMxfCMKrutIDPXSdpgYkmAvMFBsop+il/HJwWLc14xiNRsod4XVV5143M3pGg1wNKCifl2tTjbgoho9kFyso6RFkK28Qy3oSqZ+Sdw346M6jD6r2JVm7xsQZI7a5iR2Uq3PESkjkTP0=
31+
distributions: "sdist bdist_wheel"
3132
on:
3233
tags: true
3334
condition: $BUILD = True

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ For more details refer to the [documentation](https://softwarequtech.github.io/S
66
Upcoming
77
--------
88

9+
2019-10-08 (v3.0.3)
10+
-------------------
11+
- Fixed bug that mixes up return messages for different application IDs
12+
913
2019-05-29 (v3.0.2)
1014
-------------------
1115
- Updated coinflip example and added CI.

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include requirements.txt

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
PYTHON = python3
22
PIP = pip3
3-
CQC_DIR = cqc
3+
CQC_DIR = cqc
4+
EXAMPLES = examples
45

56
clean: _clear_pyc _clear_build
67

78
_clear_pyc:
89
@find . -name '*.pyc' -delete
910

1011
lint:
11-
@${PYTHON} -m flake8 ${CQC_DIR}
12+
@${PYTHON} -m flake8 ${CQC_DIR} ${EXAMPLES}
1213

1314
python-deps:
1415
@cat requirements.txt | xargs -n 1 -L 1 $(PIP) install

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# CQC (3.0.3)
2+
13
The classical-quantum combiner (CQC) interface is an interface between higher layers and hardware in a Quantum Internet. It comes with a Python, C and Rust library for constructing CQC messages. The Python library is definitely the best place to get started.
24

35
Documentation of CQC can be found at https://softwarequtech.github.io/SimulaQron/html/CQCInterface.html

cqc/MessageHandler.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2727
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

29-
from abc import ABC, abstractmethod
3029
import logging
30+
from collections import defaultdict
31+
from abc import ABC, abstractmethod
3132

3233
from cqc.cqcHeader import (
3334
CQCCmdHeader,
@@ -152,43 +153,44 @@ def __init__(self, factory):
152153

153154
# Convenience
154155
self.name = factory.name
155-
self.return_messages = [] # List of all cqc messages to return
156+
self.return_messages = defaultdict(list) # Dictionary of all cqc messages to return per app_id
156157

157158
@inlineCallbacks
158159
def handle_cqc_message(self, header, message, transport=None):
159160
"""
160161
This calls the correct method to handle the cqcmessage, based on the type specified in the header
161162
"""
162-
self.return_messages = []
163+
self.return_messages[header.app_id] = []
163164
if header.tp in self.messageHandlers:
164165
try:
165166
should_notify = yield self.messageHandlers[header.tp](header, message)
166167
if should_notify:
167168
# Send a notification that we are done if successful
168169
logging.debug("CQC %s: Command successful, sent done.", self.name)
169-
self.return_messages.append(
170+
self.return_messages[header.app_id].append(
170171
self.create_return_message(header.app_id, CQC_TP_DONE, cqc_version=header.version))
171172
except UnknownQubitError:
172173
logging.error("CQC {}: Couldn't find qubit with given ID".format(self.name))
173-
self.return_messages.append(
174+
self.return_messages[header.app_id].append(
174175
self.create_return_message(header.app_id, CQC_ERR_UNKNOWN, cqc_version=header.version))
175176
except NotImplementedError:
176177
logging.error("CQC {}: Command not implemented yet".format(self.name))
177-
self.return_messages.append(
178+
self.return_messages[header.app_id].append(
178179
self.create_return_message(header.app_id, CQC_ERR_UNSUPP, cqc_version=header.version))
179180
except Exception as err:
180181
logging.error(
181182
"CQC {}: Got the following unexpected error when handling CQC message: {}".format(self.name, err)
182183
)
183-
self.return_messages.append(
184+
self.return_messages[header.app_id].append(
184185
self.create_return_message(header.app_id, CQC_ERR_GENERAL, cqc_version=header.version))
185186
else:
186187
logging.error("CQC %s: Could not find cqc type %d in handlers.", self.name, header.yp)
187-
self.return_messages.append(
188+
self.return_messages[header.app_id].append(
188189
self.create_return_message(header.app_id, CQC_ERR_UNSUPP, cqc_version=header.version))
189190

190-
def retrieve_return_messages(self):
191-
return self.return_messages
191+
def retrieve_return_messages(self, app_id):
192+
"""Retrieve the return messages of a given app_id"""
193+
return self.return_messages[app_id]
192194

193195
@staticmethod
194196
def create_return_message(app_id, msg_type, length=0, cqc_version=CQC_VERSION):
@@ -278,13 +280,13 @@ def _process_command(self, cqc_header, length, data, is_locked=False):
278280
if cmd.instr not in self.commandHandlers:
279281
logging.debug("CQC {}: Unknown command {}".format(self.name, cmd.instr))
280282
msg = self.create_return_message(cqc_header.app_id, CQC_ERR_UNSUPP, cqc_version=cqc_header.version)
281-
self.return_messages.append(msg)
283+
self.return_messages[cqc_header.app_id].append(msg)
282284
return False, 0
283285
try:
284286
succ = yield self.commandHandlers[cmd.instr](cqc_header, cmd, xtra)
285287
except NotImplementedError:
286288
logging.error("CQC {}: Command not implemented yet".format(self.name))
287-
self.return_messages.append(
289+
self.return_messages[cqc_header.app_id].append(
288290
self.create_return_message(cqc_header.app_id, CQC_ERR_UNSUPP, cqc_version=cqc_header.verstion))
289291
return False, 0
290292
except Exception as err:
@@ -294,7 +296,7 @@ def _process_command(self, cqc_header, length, data, is_locked=False):
294296
)
295297
)
296298
msg = self.create_return_message(cqc_header.app_id, CQC_ERR_GENERAL, cqc_version=cqc_header.version)
297-
self.return_messages.append(msg)
299+
self.return_messages[cqc_header.app_id].append(msg)
298300
return False, 0
299301
if succ is False: # only if it explicitly is false, if succ is None then we assume it went fine
300302
return False, 0
@@ -319,7 +321,7 @@ def _process_command(self, cqc_header, length, data, is_locked=False):
319321
"CQC {}: Got the following unexpected error when process commands: {}".format(self.name, err)
320322
)
321323
msg = self.create_return_message(cqc_header.app_id, CQC_ERR_GENERAL, cqc_version=cqc_header.version)
322-
self.return_messages.append(msg)
324+
self.return_messages[cqc_header.app_id].append(msg)
323325
return False, 0
324326

325327
should_notify = should_notify or retNotify
@@ -340,7 +342,7 @@ def handle_factory(self, header, data):
340342
# Get factory header
341343
if len(data) < header.length:
342344
logging.debug("CQC %s: Missing header(s) in factory", self.name)
343-
self.return_messages.append(
345+
self.return_messages[header.app_id].append(
344346
self.create_return_message(header.app_id, CQC_ERR_UNSUPP, cqc_version=header.version))
345347
return False
346348
fact_header = CQCFactoryHeader(data[:fact_l])
@@ -363,7 +365,7 @@ def handle_factory(self, header, data):
363365
logging.error(
364366
"CQC {}: Got the following unexpected error when processing factory: {}".format(self.name, err)
365367
)
366-
self.return_messages.append(
368+
self.return_messages[header.app_id].append(
367369
self.create_return_message(header.app_id, CQC_ERR_GENERAL, cqc_version=header.version))
368370
return False
369371

cqc/Protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def dataReceived(self, data):
153153
def _parseData(self, header, data):
154154
try:
155155
yield self.messageHandler.handle_cqc_message(header, data)
156-
messages = self.messageHandler.retrieve_return_messages()
156+
messages = self.messageHandler.retrieve_return_messages(header.app_id)
157157
except Exception as e:
158158
raise e
159159

cqc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.0.2'
1+
__version__ = '3.0.3'

cqc/pythonLib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def readMessage(self, maxsize=192): # WHAT IS GOOD SIZE?
846846
currHeader = CQCHeader(rawHeader)
847847

848848
# Remove the header from the buffer
849-
self.buf = self.buf[CQC_HDR_LENGTH : len(self.buf)]
849+
self.buf = self.buf[CQC_HDR_LENGTH:len(self.buf)]
850850

851851
# Check for error
852852
self.check_error(currHeader)

0 commit comments

Comments
 (0)