sia-script 0.8.3__tar.gz → 0.8.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sia-script
3
- Version: 0.8.3
3
+ Version: 0.8.4
4
4
  Summary: SIA — Simplified Integrated Architecture: SiaNTT, SIA-ELS (ABAP interpreter), the HDQS server client, and hdqs_engine (offline statevector quantum simulator — no server or API token required)
5
5
  Author-email: Sia Software Innovations Private Limited <info@siasoftwareinnovations.com>
6
6
  License: # PROPRIETARY SOFTWARE LICENSE
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sia-script"
7
- version = "0.8.3"
7
+ version = "0.8.4"
8
8
  description = "SIA — Simplified Integrated Architecture: SiaNTT, SIA-ELS (ABAP interpreter), the HDQS server client, and hdqs_engine (offline statevector quantum simulator — no server or API token required)"
9
9
  authors = [
10
10
  { name = "Sia Software Innovations Private Limited", email = "info@siasoftwareinnovations.com" }
@@ -174,6 +174,7 @@ try:
174
174
  random_state,
175
175
  partial_trace, # Partial trace utility
176
176
  to_numpy, # backend array -> numpy (works without PyTorch)
177
+ to_tensor, # numpy/list -> torch tensor on a given device
177
178
  is_tensor,
178
179
 
179
180
  # Noise channel factories (CPTP-verified as of engine v0.4.0)
@@ -1259,6 +1259,83 @@ class HDQS:
1259
1259
  return (f"HDQS(num_qubits={self.num_qubits}, mode={mode}, "
1260
1260
  f"backend={self.backend}, device={self._device})")
1261
1261
 
1262
+ # -- display helpers ------------------------------------------------------
1263
+
1264
+ @staticmethod
1265
+ def fmt_amp(a: complex, tol: float = 1e-10) -> str:
1266
+ """Format one complex amplitude in physics notation a+bi
1267
+ (not Python's a+bj).
1268
+
1269
+ Examples
1270
+ --------
1271
+ >>> HDQS.fmt_amp(0.707107+0j) '0.707107'
1272
+ >>> HDQS.fmt_amp(0+0.707107j) '0.707107i'
1273
+ >>> HDQS.fmt_amp(0.5+0.5j) '0.5000+0.5000i'
1274
+ >>> HDQS.fmt_amp(-0.5+0.5j) '-0.5000+0.5000i'
1275
+ """
1276
+ r, i = float(a.real), float(a.imag)
1277
+ r_zero = abs(r) < tol
1278
+ i_zero = abs(i) < tol
1279
+ if r_zero and i_zero:
1280
+ return "0"
1281
+ if i_zero:
1282
+ return f"{r:.6g}"
1283
+ if r_zero:
1284
+ return f"{i:.6g}i"
1285
+ sign = "+" if i >= 0 else "-"
1286
+ return f"{r:.6g}{sign}{abs(i):.6g}i"
1287
+
1288
+ def show_state(self, label: Optional[str] = None,
1289
+ tol: float = 1e-9, show_zeros: bool = False) -> "HDQS":
1290
+ """Print the statevector as a State | Amplitude | Probability table.
1291
+
1292
+ Amplitudes are in physics notation a+bi (not Python's a+bj).
1293
+ Returns self so it can be inserted into a gate chain without
1294
+ interrupting it.
1295
+
1296
+ Args:
1297
+ label: heading printed above the table (default: repr(self)).
1298
+ tol: amplitudes with |a| < tol are treated as zero and
1299
+ omitted unless show_zeros=True.
1300
+ show_zeros: if True, include all basis states even when P=0.
1301
+
1302
+ Examples
1303
+ --------
1304
+ >>> HDQS(1).h(0).show_state("H|0⟩")
1305
+ H|0⟩
1306
+ State Amplitude Prob
1307
+ ────────────────────────────────
1308
+ |0⟩ 0.707+0.000i 50.0%
1309
+ |1⟩ 0.707+0.000i 50.0%
1310
+
1311
+ >>> HDQS(1).h(0).s(0).show_state("S|+⟩")
1312
+ S|+⟩
1313
+ State Amplitude Prob
1314
+ ────────────────────────────────
1315
+ |0⟩ 0.707+0.000i 50.0%
1316
+ |1⟩ 0.000+0.707i 50.0%
1317
+ """
1318
+ if label is None:
1319
+ label = repr(self)
1320
+ sv = self.state
1321
+ if sv is None:
1322
+ print(f"{label}\n[mixed state — show_state requires a pure state]\n")
1323
+ return self
1324
+ sv_np = to_numpy(sv)
1325
+ n = self.num_qubits
1326
+ print(label)
1327
+ print(f"{'State':<8} {'Amplitude':>18} {'Prob':>8}")
1328
+ print("─" * 37)
1329
+ for idx, a in enumerate(sv_np):
1330
+ prob = abs(a) ** 2
1331
+ if prob < tol ** 2 and not show_zeros:
1332
+ continue
1333
+ ket = f"|{idx:0{n}b}⟩"
1334
+ amp = f"{a.real:.3f}{a.imag:+.3f}i"
1335
+ print(f"{ket:<8} {amp:>18} {prob*100:>7.1f}%")
1336
+ print()
1337
+ return self
1338
+
1262
1339
 
1263
1340
  StatevectorEngine = HDQS # legacy alias
1264
1341
 
@@ -2022,6 +2099,7 @@ __all__ = [
2022
2099
  "qaoa_maxcut", "qaoa_state", "maxcut_expectation",
2023
2100
  # Protocols
2024
2101
  "bb84", "e91", "qss",
2102
+ # (fmt_amp and show_state are methods on HDQS — access as HDQS.fmt_amp / q.show_state)
2025
2103
  # PyTorch (optional)
2026
2104
  "QuantumLayer",
2027
2105
  # Backend flags
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sia-script
3
- Version: 0.8.3
3
+ Version: 0.8.4
4
4
  Summary: SIA — Simplified Integrated Architecture: SiaNTT, SIA-ELS (ABAP interpreter), the HDQS server client, and hdqs_engine (offline statevector quantum simulator — no server or API token required)
5
5
  Author-email: Sia Software Innovations Private Limited <info@siasoftwareinnovations.com>
6
6
  License: # PROPRIETARY SOFTWARE LICENSE
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes