Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions README_INTERNAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ result = client.job_result(job_id, job_request)
result = client.wait_for_job_result(job_id, job_request)
```

## Compute Node Config for HPCQC

The following two environment variables can be set if needed

- The queue name where the Quantum Offload Listener is accepting the requests can be set using
`MQSS_OFFLOAD_LISTENER_QUEUE_NAME`
- Path to the file where RabbitMQ connection configuration can be set using
`MQSS_CLIENT_RMQ_CONN_CONFIG_FILE`

## Setting up development environment

- The repository uses [`uv`](https://docs.astral.sh/uv/) for python package management.
Expand Down
28 changes: 18 additions & 10 deletions mqss_client/comm/rmq_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""RabbitMQ Client for HPCQC"""

import os
from dataclasses import dataclass
from json import load
from typing import Any, Dict, Optional
Expand All @@ -18,11 +19,16 @@ def __init__(self, token: str) -> None:
self.token = token
self.connection = None
self.channel = None
self.conn_config = ConnectionConfiguration()
self.conn_config = (
ConnectionConfiguration()
if os.environ.get("MQSS_CLIENT_RMQ_CONN_CONFIG_FILE") is None
else ConnectionConfiguration.from_json_file(
os.environ["MQSS_CLIENT_RMQ_CONN_CONFIG_FILE"]
)
)

def connect(self) -> None:
"""Connect to RabbitMQ server"""
print(f"Connecting to RabbitMQ server {self.conn_config} ...")
self.connection = create_rmq_connection(self.conn_config)
assert self.connection is not None
self.channel = self.connection.channel()
Expand All @@ -38,8 +44,12 @@ def send(self, data: str, destination: str) -> bool:
"""Send data to RabbitMQ server"""
if not self.channel:
return False

if self.channel.is_closed:
self.channel = self.connection.channel()

try:
self.channel.queue_declare(queue=destination, durable=True)
self.channel.queue_declare(queue=destination)
self.channel.basic_publish(
exchange="", routing_key=destination, body=data, mandatory=True
)
Expand All @@ -54,20 +64,18 @@ def receive(
if not self.channel:
return None

if self.channel.is_closed:
self.channel = self.connection.channel()

response = None
self.channel.queue_declare(queue=source, durable=True)
self.channel.queue_declare(queue=source)
for method_frame, _, body in self.channel.consume(
queue=source,
inactivity_timeout=1,
auto_ack=True,
):
if body is not None:
response = body.decode()
print(f"Received message: {body}")
print(f"Decoded message: {response}")
print(f"Decoded message type: {type(response)}")
print(f"Decoded message str: {str(response)}")

break

return response
Expand All @@ -76,7 +84,7 @@ def declare_queue(self, queue_name: str) -> None:
"""Declare a queue"""
if not self.channel:
return
self.channel.queue_declare(queue=queue_name, durable=True)
self.channel.queue_declare(queue=queue_name)

def delete_queue(self, queue_name: str) -> None:
"""Delete a queue"""
Expand Down
2 changes: 1 addition & 1 deletion mqss_client/hpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HPCOffloadClient(BaseClient):
def __init__(
self,
token: str,
offload_listener_queue_name: str = f"qd_qrequest_reception_queue_{HOSTNAME}",
offload_listener_queue_name: str = f"qoffload_api_request_reception_queue_{HOSTNAME}",
) -> None:
"""Initialize the HPC Offload Client"""
self.token = token
Expand Down
11 changes: 10 additions & 1 deletion mqss_client/mqss_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""

import json
import os
import socket
import time
from datetime import datetime
from typing import Dict, Optional, Union
Expand All @@ -21,7 +23,14 @@ def __init__(self, token: str, base_url: str, is_hpc: bool = False):
self.base_url = base_url
self.client: Union[HPCOffloadClient, RESTClient]
if is_hpc:
self.client = HPCOffloadClient(token)
HOSTNAME = socket.gethostname().replace(" ", "_")
_offload_queue_name = os.environ.get(
"MQSS_OFFLOAD_LISTENER_QUEUE_NAME",
f"qoffload_api_request_reception_queue_{HOSTNAME}",
)
self.client = HPCOffloadClient(
token, offload_listener_queue_name=_offload_queue_name
)
else:
self.client = RESTClient(token, base_url)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[project]
name = "mqss-client"
version = "0.2.0"
version = "0.2.1"
description = "A client for MQP and HPCQC"
authors = [
{name = "mqss", email = "mqss@munich-quantum-valley.de"},
Expand Down
Loading