Skip to content

Commit 5ae38e8

Browse files
authored
Add Quafu backend adapter with OpenQASM support and make t1s and t2s properties optional in BackendAdapter protocol (#12)
* feat: make t1s and t2s properties optional in BackendAdapter protocol * feat: Add Quafu backend adapter with OpenQASM support and improved error handling
1 parent 965ed63 commit 5ae38e8

File tree

6 files changed

+828
-18
lines changed

6 files changed

+828
-18
lines changed

src/qonscious/adapters/__init__.py

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
1-
from .aer_sampler_adapter import AerSamplerAdapter
2-
from .aer_simulator_adapter import AerSimulatorAdapter
3-
from .backend_adapter import BackendAdapter
4-
from .ibm_sampler_adapter import IBMSamplerAdapter
5-
from .ionq_backend_adapter import IonQBackendAdapter
6-
7-
__all__ = [
8-
"BackendAdapter",
9-
"AerSamplerAdapter",
10-
"IonQBackendAdapter",
11-
"AerSimulatorAdapter",
12-
"IBMSamplerAdapter",
13-
]
1+
# Todos los imports con manejo de errores
2+
_adapters = {}
3+
4+
try:
5+
from .aer_sampler_adapter import AerSamplerAdapter
6+
_adapters["AerSamplerAdapter"] = AerSamplerAdapter
7+
except ImportError as e:
8+
AerSamplerAdapter = None
9+
print(f"⚠️ AerSamplerAdapter no disponible: {e}")
10+
11+
try:
12+
from .aer_simulator_adapter import AerSimulatorAdapter
13+
_adapters["AerSimulatorAdapter"] = AerSimulatorAdapter
14+
except ImportError as e:
15+
AerSimulatorAdapter = None
16+
print(f"⚠️ AerSimulatorAdapter no disponible: {e}")
17+
18+
try:
19+
from .ibm_sampler_adapter import IBMSamplerAdapter
20+
_adapters["IBMSamplerAdapter"] = IBMSamplerAdapter
21+
except ImportError as e:
22+
IBMSamplerAdapter = None
23+
print(f"⚠️ IBMSamplerAdapter no disponible: {e}")
24+
25+
try:
26+
from .ionq_backend_adapter import IonQBackendAdapter
27+
_adapters["IonQBackendAdapter"] = IonQBackendAdapter
28+
except ImportError as e:
29+
IonQBackendAdapter = None
30+
print(f"⚠️ IonQBackendAdapter no disponible: {e}")
31+
32+
try:
33+
from .quafu_backend_adapter import QuafuBackendAdapter
34+
_adapters["QuafuBackendAdapter"] = QuafuBackendAdapter
35+
except ImportError as e:
36+
QuafuBackendAdapter = None
37+
print(f"⚠️ QuafuBackendAdapter no disponible: {e}")
38+
39+
# BackendAdapter es esencial - si falla, hay un problema grave
40+
try:
41+
from .backend_adapter import BackendAdapter
42+
_adapters["BackendAdapter"] = BackendAdapter
43+
except ImportError as e:
44+
raise ImportError(f"❌ BackendAdapter esencial no disponible: {e}")
45+
46+
# Hacer disponibles todos en el namespace
47+
globals().update(_adapters)
48+
49+
# Solo exportar los que se importaron correctamente
50+
__all__ = list(_adapters.keys())
51+
52+
# Información de disponibilidad
53+
available_adapters = {name: adapter is not None for name, adapter in _adapters.items()}
54+
__all__.append("available_adapters")
55+
56+
print(f"✅ Adapters cargados: {len(_adapters)}/{len(__all__)-1}")

src/qonscious/adapters/backend_adapter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ def n_qubits(self) -> int:
2020
...
2121

2222
@property
23-
def t1s(self) -> dict[int, float]:
23+
def t1s(self) -> dict[int, float] | None:
2424
"""
2525
Returns:
26-
dict[int, float]: The T1 (relaxation time) for each qubit.
26+
dict[int, float] | None: The T1 (relaxation time) for each qubit,
27+
or None if not available.
2728
"""
2829
...
2930

3031
@property
31-
def t2s(self) -> dict[int, float]:
32+
def t2s(self) -> dict[int, float] | None:
3233
"""
3334
Returns:
34-
dict[int, float]: The T2 (dephasing time) for each qubit.
35+
dict[int, float] | None: The T2 (dephasing time) for each qubit,
36+
or None if not available.
3537
"""
3638
...
3739

0 commit comments

Comments
 (0)