1313import functools
1414import hashlib
1515from datetime import datetime
16- from typing import TYPE_CHECKING , Any , Callable
16+ from typing import TYPE_CHECKING , Any
1717
1818from qbom .adapters .base import Adapter
1919from qbom .core .models import (
@@ -74,8 +74,7 @@ def _circuit_to_model(circuit: Any) -> Circuit:
7474 num_qubits = len (all_qubits )
7575
7676 # Count measurement operations for classical bits
77- num_clbits = sum (1 for op in circuit .all_operations ()
78- if isinstance (op .gate , cirq .MeasurementGate ))
77+ num_clbits = sum (1 for op in circuit .all_operations () if isinstance (op .gate , cirq .MeasurementGate ))
7978
8079 return Circuit (
8180 name = None ,
@@ -86,7 +85,7 @@ def _circuit_to_model(circuit: Any) -> Circuit:
8685 hash = _hash_circuit (circuit ),
8786 qasm = None , # Cirq uses different format
8887 )
89- except Exception as e :
88+ except Exception :
9089 # Fallback minimal circuit
9190 return Circuit (
9291 num_qubits = 0 ,
@@ -102,20 +101,20 @@ def _extract_counts_from_result(result: Any, num_shots: int) -> Counts:
102101 # Cirq results have measurements as numpy arrays
103102 counts_dict : dict [str , int ] = {}
104103
105- if hasattr (result , ' measurements' ):
104+ if hasattr (result , " measurements" ):
106105 # Get all measurement keys
107106 for key in result .measurements :
108107 measurement_array = result .measurements [key ]
109108 # Convert each shot to bitstring
110109 for shot in measurement_array :
111- bitstring = '' .join (str (bit ) for bit in shot )
110+ bitstring = "" .join (str (bit ) for bit in shot )
112111 counts_dict [bitstring ] = counts_dict .get (bitstring , 0 ) + 1
113112
114113 if not counts_dict :
115114 # Try histogram method if available
116- if hasattr (result , ' histogram' ):
115+ if hasattr (result , " histogram" ):
117116 hist = result .histogram (key = list (result .measurements .keys ())[0 ])
118- counts_dict = {format (k , 'b' ): v for k , v in hist .items ()}
117+ counts_dict = {format (k , "b" ): v for k , v in hist .items ()}
119118
120119 return Counts (raw = counts_dict , shots = num_shots )
121120 except Exception :
@@ -194,9 +193,7 @@ def wrapped_run(
194193 submitted_at = datetime .utcnow ()
195194
196195 # Run original
197- result = original_run (
198- self_sim , program , param_resolver , repetitions , ** kwargs
199- )
196+ result = original_run (self_sim , program , param_resolver , repetitions , ** kwargs )
200197
201198 completed_at = datetime .utcnow ()
202199
@@ -210,9 +207,7 @@ def wrapped_run(
210207
211208 # Capture results
212209 counts = _extract_counts_from_result (result , repetitions )
213- result_hash = hashlib .sha256 (
214- str (sorted (counts .raw .items ())).encode ()
215- ).hexdigest ()[:16 ]
210+ result_hash = hashlib .sha256 (str (sorted (counts .raw .items ())).encode ()).hexdigest ()[:16 ]
216211
217212 qbom_result = Result (counts = counts , hash = result_hash )
218213 builder .set_result (qbom_result )
@@ -260,9 +255,7 @@ def wrapped_simulate(
260255 builder .set_hardware (hardware )
261256
262257 # Run original
263- result = original_simulate (
264- self_sim , program , param_resolver , qubit_order , initial_state
265- )
258+ result = original_simulate (self_sim , program , param_resolver , qubit_order , initial_state )
266259
267260 # For state vector simulation, we capture the final state
268261 execution = Execution (
@@ -285,7 +278,7 @@ def wrapped_simulate(
285278 def _hook_density_matrix_simulator (self , cirq : Any ) -> None :
286279 """Hook DensityMatrixSimulator if available."""
287280 try :
288- if hasattr (cirq , ' DensityMatrixSimulator' ):
281+ if hasattr (cirq , " DensityMatrixSimulator" ):
289282 original_run = cirq .DensityMatrixSimulator .run
290283 adapter = self
291284
@@ -312,9 +305,7 @@ def wrapped_run(
312305 builder .set_hardware (hardware )
313306
314307 submitted_at = datetime .utcnow ()
315- result = original_run (
316- self_sim , program , param_resolver , repetitions , ** kwargs
317- )
308+ result = original_run (self_sim , program , param_resolver , repetitions , ** kwargs )
318309 completed_at = datetime .utcnow ()
319310
320311 execution = Execution (
@@ -326,9 +317,7 @@ def wrapped_run(
326317
327318 # Capture results
328319 counts = _extract_counts_from_result (result , repetitions )
329- result_hash = hashlib .sha256 (
330- str (sorted (counts .raw .items ())).encode ()
331- ).hexdigest ()[:16 ]
320+ result_hash = hashlib .sha256 (str (sorted (counts .raw .items ())).encode ()).hexdigest ()[:16 ]
332321
333322 qbom_result = Result (counts = counts , hash = result_hash )
334323 builder .set_result (qbom_result )
@@ -351,7 +340,7 @@ def _hook_quantum_engine(self) -> None:
351340 try :
352341 import cirq_google
353342
354- if hasattr (cirq_google , ' Engine' ):
343+ if hasattr (cirq_google , " Engine" ):
355344 # Hook the sampler's run method
356345 original_run = cirq_google .Engine .get_sampler
357346 adapter = self
0 commit comments