Skip to content

Commit

Permalink
Run formatting via Black
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-oqc committed Nov 15, 2024
1 parent b7faec5 commit 274b772
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
5 changes: 1 addition & 4 deletions src/QAT_RPC/qat_rpc/utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ def hardware_reloaded(self, outcome: BinaryMutableOutcome): ...


class PrometheusReceiver(ReceiverBackend):
def __init__(
self,
port: int = PROMETHEUS_PORT
):
def __init__(self, port: int = PROMETHEUS_PORT):
super(PrometheusReceiver, self).__init__()
start_http_server(port)
log.info(f"Starting Prometheus metrics exporter on port {port}.")
Expand Down
38 changes: 26 additions & 12 deletions src/QAT_RPC/qat_rpc/zmq/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ def main():
else:
try:
if not (1024 < int(receiver_port) < 49152):
raise ValueError("Receiver must be configured to run on a valid port number between 1024 and 49152.")
raise ValueError(
"Receiver must be configured to run on a valid port number between 1024 and 49152."
)
log.info(f"Receiver server is configured to start on port {receiver_port}.")
except ValueError as e:
log.warning(f"{e}")
receiver_port = 5556
log.info(f"Defaulting receiver to run on port {receiver_port}.")
else:
receiver_port = 5556

if metrics_port is not None:
try:
int(metrics_port)
Expand All @@ -57,28 +59,36 @@ def main():
metrics_port = PROMETHEUS_PORT
log.info(f"Defaulting metrics exporter to run on port {metrics_port}")
else:
try:
if (int(metrics_port) == int(receiver_port)):
raise ValueError(f"Metrics exporter cannot run on port {metrics_port}, it must be set to a different value to the receiver port.")
try:
if int(metrics_port) == int(receiver_port):
raise ValueError(
f"Metrics exporter cannot run on port {metrics_port}, it must be set to a different value to the receiver port."
)
elif not (1024 < int(metrics_port) < 49152):
raise ValueError("Metrics exporter must be configured to run on a valid port number between 1024 and 49152.")
raise ValueError(
"Metrics exporter must be configured to run on a valid port number between 1024 and 49152."
)
log.info(f"Metrics exporter is configured to start on port {metrics_port}.")
except ValueError as e:
log.warning(f"{e}")
metrics_port = PROMETHEUS_PORT
log.info(f"Defaulting metrics exporter to run on port {metrics_port}.")
else:
metrics_port = PROMETHEUS_PORT

try:
if int(metrics_port) == int(receiver_port):
raise ValueError
except ValueError:
log.warning("The receiver and metrics exporter have been configured to run on the same port.")
log.warning(
"The receiver and metrics exporter have been configured to run on the same port."
)
receiver_port = 5556
metrics_port = PROMETHEUS_PORT
log.info(f"Defaulting receiver to run on port {receiver_port} and metrics exporter to run on port {metrics_port}.")

log.info(
f"Defaulting receiver to run on port {receiver_port} and metrics exporter to run on port {metrics_port}."
)

metric_exporter = MetricExporter(backend=PrometheusReceiver(port=int(metrics_port)))

if (calibration_file := os.getenv("TOSHIKO_CAL")) is not None:
Expand All @@ -91,10 +101,14 @@ def main():
hw = Calibratable.load_calibration_from_file(str(calibration_file))
log.debug("Loaded")

receiver = ZMQServer(hardware=hw, server_port=receiver_port, metric_exporter=metric_exporter)
receiver = ZMQServer(
hardware=hw, server_port=receiver_port, metric_exporter=metric_exporter
)
gk = GracefulKill(receiver)

log.info(f"Starting QAT receiver on port {str(receiver._port)} with {type(receiver._hardware)} hardware.")
log.info(
f"Starting QAT receiver on port {str(receiver._port)} with {type(receiver._hardware)} hardware."
)
receiver.run()


Expand Down
13 changes: 3 additions & 10 deletions src/QAT_RPC/qat_rpc/zmq/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ class Messages(Enum):

class ZMQBase:
def __init__(
self,
socket_type: zmq.SocketType,
ip_address: str = "127.0.0.1",
port: str = "5556"
self, socket_type: zmq.SocketType, ip_address: str = "127.0.0.1", port: str = "5556"
):
self._context = zmq.Context()
self._socket = self._context.socket(socket_type)
Expand Down Expand Up @@ -77,7 +74,7 @@ def __init__(
self,
hardware: Optional[QuantumHardwareModel] = None,
server_port: Optional[str] = None,
metric_exporter: Optional[MetricExporter] = None
metric_exporter: Optional[MetricExporter] = None,
):
super().__init__(socket_type=zmq.REP, port=server_port)
self._metric = metric_exporter
Expand Down Expand Up @@ -161,11 +158,7 @@ def stop(self):


class ZMQClient(ZMQBase):
def __init__(
self,
client_ip: Optional[str] = None,
client_port: Optional[str] = None
):
def __init__(self, client_ip: Optional[str] = None, client_port: Optional[str] = None):
super().__init__(socket_type=zmq.REQ, ip_address=client_ip, port=client_port)
self._socket.setsockopt(zmq.LINGER, 0)
self._socket.connect(self.address)
Expand Down

0 comments on commit 274b772

Please sign in to comment.