References
Gates#
Gates is the entry point for applying gates to a circuit.
It records the gate on the active tape, attaches any requested noise, and routes the call to
either UnitaryGates or PulseGates depending on the pulse keyword.
The two backends below, and the matrix-level classes in jaqsi.gateset, are what Gates
dispatches to; call them directly only when you need the operation object itself (for
observables, .dagger() / .power(), or matrix algebra).
As the structure of the different classes used to realize pulse and unitary gates can be a bit confusing, the following diagram might help:

The entry point for applying gates to a circuit.
Call gates as Gates.<Name>(...) inside a circuit function; the call is
routed to either UnitaryGates or PulseGates depending on the pulse
keyword. Prefer this over calling the backends (UnitaryGates,
PulseGates) or the matrix-level classes in :mod:jaqsi.gateset directly,
so that the same circuit can run at either level.
During circuit building, the pulse manager can be activated via
pulse_manager_context, which slices the global model pulse parameters
and passes them to each gate. Model pulse parameters act as element-wise
scalers on the gate's optimized pulse parameters.
Parameters#
pulse : bool, optional
Whether to run the gate at pulse level (PulseGates) instead of as an
ideal unitary (UnitaryGates). Defaults to False.
Examples#
Gates.RX(w, wires) Gates.RX(w, wires, pulse=True) Gates.RX(w, wires, pulse=True, pulse_params=pulse_params)
Source code in jaqsi/gates.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
pulse_manager_context(pulse_params)
classmethod
#
Temporarily set the global pulse manager for circuit building.
Source code in jaqsi/gates.py
Unitary Gates#
Collection of unitary quantum gates with optional noise simulation.
Source code in jaqsi/unitary.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
CPhase(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled phase shift gate with optional noise.
This is a generalization of the CZ gate, applying a phase shift of exp(i*w) to the |11⟩ state. When w=π, this reduces to CZ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Phase shift angle. |
required |
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
CRX(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled X-rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
CRY(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled Y-rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
CRZ(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled Z-rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
CX(wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-NOT (CNOT) gate with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
CY(wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-Y gate with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
CZ(wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-Z gate with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
GateError(w, noise_params=None, random_key=None)
staticmethod
#
Apply gate error noise to rotation angle(s).
Adds Gaussian noise to gate rotation angles to simulate imperfect gate implementations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle(s) in radians. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Dictionary with optional "GateError" key specifying standard deviation of Gaussian noise. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for stochastic noise generation. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, PRNGKey]
|
Tuple[jnp.ndarray, jax.random.PRNGKey]: Tuple containing: - Modified rotation angle(s) with applied noise - Updated JAX random key |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If noise_params contains "GateError" but random_key is None. |
Source code in jaqsi/unitary.py
H(wires, noise_params=None, random_key=None)
staticmethod
#
Apply Hadamard gate with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
NQubitDepolarizingChannel(p, wires)
staticmethod
#
Generate Kraus operators for n-qubit depolarizing channel.
The n-qubit depolarizing channel models uniform depolarizing noise acting on n qubits simultaneously, useful for simulating realistic multi-qubit noise affecting entangling gates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Total probability of depolarizing error (0 ≤ p ≤ 1). |
required |
wires
|
List[int]
|
Qubit indices on which the channel acts. Must contain at least 2 qubits. |
required |
Returns:
| Type | Description |
|---|---|
QubitChannel
|
noise.QubitChannel: QubitChannel with Kraus operators representing the depolarizing noise channel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If p is not in [0, 1] or if fewer than 2 qubits provided. |
Source code in jaqsi/unitary.py
Noise(wires, noise_params=None)
staticmethod
#
Apply noise channels to specified qubits.
Applies various single-qubit and multi-qubit noise channels based on the provided noise parameters dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Qubit index or list of qubit indices to apply noise to. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Dictionary of noise parameters. Supported keys: - "BitFlip" (float): Bit flip error probability - "PhaseFlip" (float): Phase flip error probability - "Depolarizing" (float): Single-qubit depolarizing probability - "MultiQubitDepolarizing" (float): Multi-qubit depolarizing probability (applies if len(wires) > 1) All parameters default to 0.0 if not provided. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Noise channels are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
PauliRot(theta, pauli, wires, noise_params=None, random_key=None)
staticmethod
#
Apply general rotation gate with optional noise.
Applies a three-angle rotation Rot(phi, theta, omega) with optional gate errors and noise channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
Union[float, ndarray, List[float]]
|
Second rotation angle. |
required |
pauli
|
str
|
Pauli operator to apply. Must be "X", "Y", or "Z". |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices to apply rotation to. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. Supports BitFlip, PhaseFlip, Depolarizing, and GateError. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
RX(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply X-axis rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
RXX(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit XX rotation with optional noise.
Implements RXX(theta) = exp(-i theta/2 X ⊗ X).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Two qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
RY(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply Y-axis rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
RYY(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit YY rotation with optional noise.
Implements RYY(theta) = exp(-i theta/2 Y ⊗ Y).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Two qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
RZ(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply Z-axis rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
RZX(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit ZX rotation with optional noise.
Implements RZX(theta) = exp(-i theta/2 Z ⊗ X), with Z acting
on the first wire and X on the second wire.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Two qubit indices |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
RZZ(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit ZZ rotation with optional noise.
Implements RZZ(theta) = exp(-i theta/2 Z ⊗ Z).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Two qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
Rot(phi, theta, omega, wires, noise_params=None, random_key=None)
staticmethod
#
Apply general rotation gate with optional noise.
Applies a three-angle rotation Rot(phi, theta, omega) with optional gate errors and noise channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
Union[float, ndarray, List[float]]
|
First rotation angle. |
required |
theta
|
Union[float, ndarray, List[float]]
|
Second rotation angle. |
required |
omega
|
Union[float, ndarray, List[float]]
|
Third rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices to apply rotation to. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. Supports BitFlip, PhaseFlip, Depolarizing, and GateError. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in jaqsi/unitary.py
Pulse Gates#
Pulse-level implementations of quantum gates.
Implements quantum gates using time-dependent Hamiltonians and pulse
sequences, following the approach from https://doi.org/10.5445/IR/1000184129.
The active pulse envelope is selected via
:meth:PulseInformation.set_envelope.
Attributes:
| Name | Type | Description |
|---|---|---|
omega_q |
Qubit frequency (10π). |
|
omega_c |
Carrier frequency (10π). |
|
_active_envelope |
str
|
Name of the currently active envelope shape. |
Source code in jaqsi/pulses.py
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 | |
CPhase(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled phase shift via decomposition.
Decomposes CPhase(φ) into RZ and CX gates: RZ(φ/2) on control, RZ(φ/2) on target, CX, RZ(-φ/2) on target, CX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Phase shift angle in radians. |
required |
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in jaqsi/pulses.py
CRX(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-RX via decomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Source code in jaqsi/pulses.py
CRY(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-RY via decomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in jaqsi/pulses.py
CRZ(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-RZ via decomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in jaqsi/pulses.py
CX(wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply CNOT gate via decomposition: H(target) · CZ · H(target).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate is applied in-place to the circuit. |
Source code in jaqsi/pulses.py
CY(wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-Y via decomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Source code in jaqsi/pulses.py
CZ(wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-Z using ZZ coupling Hamiltonian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
List[int]
|
Control and target qubit indices. |
required |
pulse_params
|
Optional[float]
|
Time or duration parameter for the pulse evolution. If None, uses optimized value. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Source code in jaqsi/pulses.py
H(wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply Hadamard gate using pulse decomposition.
Decomposes as RZ(π) · RY(π/2) followed by a correction phase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Source code in jaqsi/pulses.py
PauliRot(pauli, theta, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Not implemented as a PulseGate.
Source code in jaqsi/pulses.py
RX(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply X-axis rotation using the active pulse envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
pulse_params
|
Optional[ndarray]
|
Envelope parameters |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in jaqsi/pulses.py
RXX(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit RXX rotation via decomposition.
Implements RXX(theta) = exp(-i theta/2 X ⊗ X) as
(H ⊗ H) · RZZ(theta) · (H ⊗ H).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Two qubit indices. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Source code in jaqsi/pulses.py
RY(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply Y-axis rotation using the active pulse envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
pulse_params
|
Optional[ndarray]
|
Envelope parameters |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in jaqsi/pulses.py
RYY(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit RYY rotation via decomposition.
Implements RYY(theta) = exp(-i theta/2 Y ⊗ Y) by conjugating the
RZZ skeleton with RX(pi/2) rotations on both wires.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Two qubit indices. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Source code in jaqsi/pulses.py
RZ(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply Z-axis rotation using pulse-level implementation.
Implements RZ rotation using virtual Z rotations (phase tracking) without physical pulse application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices to apply rotation to. |
required |
pulse_params
|
Optional[float]
|
Duration parameter for the pulse. Rotation angle = w * 2 * pulse_params. Defaults to 0.5 if None. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate is applied in-place to the circuit. |
Source code in jaqsi/pulses.py
RZX(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit RZX rotation via decomposition.
Implements RZX(theta) = exp(-i theta/2 Z ⊗ X) (Z on the first
wire, X on the second) by conjugating the RZZ skeleton with a
Hadamard on the target wire.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Two qubit indices |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Source code in jaqsi/pulses.py
RZZ(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit RZZ rotation via decomposition.
Implements RZZ(theta) = exp(-i theta/2 Z ⊗ Z) as
CX · RZ(theta)_target · CX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Two qubit indices. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Source code in jaqsi/pulses.py
Rot(phi, theta, omega, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply general rotation via decomposition: RZ(phi) · RY(theta) · RZ(omega).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
float
|
First rotation angle. |
required |
theta
|
float
|
Second rotation angle. |
required |
omega
|
float
|
Third rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices to apply rotation to. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gates are applied in-place to the circuit. |
Source code in jaqsi/pulses.py
Pulse Structure#
Container for hierarchical pulse parameters.
Leaf nodes hold direct parameters; composite nodes hold a list of
:class:DecompositionStep objects that describe how the gate is
built from simpler gates.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Gate identifier (e.g. |
|
decomposition |
List of :class: |
Source code in jaqsi/pulses.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
childs
property
#
Get direct children of this node.
Returns:
| Type | Description |
|---|---|
List[PulseParams]
|
List[PulseParams]: List of child PulseParams objects, or empty list if this is a leaf node. |
is_leaf
property
#
Check if this is a leaf node (direct parameters, no children).
leaf_params
property
writable
#
Get parameters from all leaf nodes.
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Concatenated parameters from all leaf nodes. |
leafs
property
#
Get all leaf nodes in the hierarchy.
Recursively collects all leaf PulseParams objects in the tree.
Returns:
| Type | Description |
|---|---|
List[PulseParams]
|
List[PulseParams]: List of unique leaf nodes. |
params
property
writable
#
Get or compute pulse parameters.
For leaf nodes, returns internal pulse parameters. For composite nodes, returns concatenated parameters from all children.
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Pulse parameters array. |
shape
property
#
Get the shape of pulse parameters.
For leaf nodes, returns list with parameter count. For composite nodes, returns nested list of child shapes.
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: Parameter shape specification. |
size
property
#
Get the total parameter count (alias for len).
__getitem__(idx)
#
Access pulse parameter(s) by index.
For leaf gates, returns the parameter at the given index. For composite gates, returns parameters of the child at the given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Index to access. |
required |
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
Union[float, jnp.ndarray]: Parameter value or child parameters. |
Source code in jaqsi/pulses.py
__init__(name='', params=None, decomposition=None)
#
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Gate name. |
''
|
params
|
Optional[ndarray]
|
Direct pulse parameters (leaf gates). Mutually exclusive with decomposition. |
None
|
decomposition
|
Optional[List[DecompositionStep]]
|
List of :class: |
None
|
Source code in jaqsi/pulses.py
__len__()
#
Get the total number of pulse parameters.
For composite gates, returns the accumulated count from all children.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Total number of pulse parameters. |
__repr__()
#
__str__()
#
split_params(params=None, leafs=False)
#
Split parameters into sub-arrays for children or leaves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Optional[ndarray]
|
Parameters to split. If None, uses internal parameters. |
None
|
leafs
|
bool
|
If True, splits across leaf nodes; if False, splits across direct children. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
List[jnp.ndarray]: List of parameter arrays for children or leaves. |
Source code in jaqsi/pulses.py
Pulse Envelope#
Registry of pulse envelope shapes.
Each envelope is a pure function (p, t, t_c) -> amplitude that
computes the pulse envelope without carrier modulation. The carrier
cos(omega_c * t + phi_c) is applied separately in the coefficient
functions built by :meth:build_coeff_fns.
Attributes:
| Name | Type | Description |
|---|---|---|
REGISTRY |
Mapping from envelope name to metadata dict containing
|
Source code in jaqsi/pulses.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
available()
staticmethod
#
build_coeff_fns(envelope_fn, omega_c, omega_q, rwa=True, frame='drive')
staticmethod
#
Build the four interaction-picture coefficient functions.
The lab-frame Hamiltonian is
H(t,Π) = H_static + Σ_j S_j(t;Π) H_j ,
S_j(t;Π) = E_j(t;Π) · cos(ω_c·t + φ_c) ,
and the interaction-picture transform with respect to
H_static = (ω_q/2)·Z produces
H̃_j(t) = exp(+i H_static t) H_j exp(-i H_static t) ,
H_I(t) = Σ_j S_j(t) H̃_j(t) .
For a single qubit driven on X, H̃_X(t) = cos(ω_q·t) X
− sin(ω_q·t) Y, so
H_I(t) = Ω(t) · cos(ω_c·t + φ) ·
[ cos(ω_q·t) · X − sin(ω_q·t) · Y ] .
rwa=True (default) drops the fast (~2·ω_q on resonance) terms and
keeps only the slow envelope, yielding the analytical RWA
H_I^RWA(t) = (Ω(t)/2) · [ cos(φ) X + sin(φ) Y ] .
For RX (φ = 0) this reduces to (Ω/2)·X; for RY
(φ = +π/2) to (Ω/2)·Y. This is dramatically cheaper to
integrate (no fast oscillations → adaptive ODE solver takes
large steps).
rwa=False keeps both the slow and the fast
counter-rotating components.
Each returned function has a unique __code__ object so the
jaqsi solver cache assigns separate compiled XLA programs per
envelope shape and per (gate, component) pair.
The rotation angle w is expected as the last element of
the parameter array p (i.e. p[-1]). Envelope parameters
occupy p[:-1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
envelope_fn
|
Callable
|
Pure envelope function |
required |
omega_c
|
float
|
Carrier frequency. |
required |
omega_q
|
float
|
Qubit frequency (interaction-picture rotation rate). |
required |
rwa
|
bool
|
When |
True
|
frame
|
str
|
Algebraic representation of the exact (non-RWA) coefficients. Mathematically equivalent options:
Ignored when |
'drive'
|
Returns:
| Type | Description |
|---|---|
Callable
|
Tuple |
Callable
|
of coefficient functions for the X- and Y-components of the |
Callable
|
RX and RY interaction-picture Hamiltonians. |
Source code in jaqsi/pulses.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
cosine(p, t, t_c)
staticmethod
#
drag(p, t, t_c)
staticmethod
#
DRAG (Derivative Removal by Adiabatic Gate). p = [A, beta, sigma].
Source code in jaqsi/pulses.py
gaussian(p, t, t_c)
staticmethod
#
get(name)
staticmethod
#
Look up envelope metadata by name.
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not registered. |
Source code in jaqsi/pulses.py
sech(p, t, t_c)
staticmethod
#
Pulse Information#
Stores pulse parameter counts and optimized pulse parameters.
Call :meth:set_envelope to switch the active pulse shape. This
rebuilds all :class:PulseParams trees so that parameter counts
and defaults match the selected envelope.
Source code in jaqsi/pulses.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 | |
get_envelope()
classmethod
#
get_frame()
classmethod
#
get_rwa()
classmethod
#
preserve_state()
classmethod
#
Temporarily preserve global pulse state across scoped mutations.
reset_defaults(envelope=None, rwa=None, frame=None)
classmethod
#
Reset pulse globals to canonical defaults or explicit values.
Source code in jaqsi/pulses.py
restore_state(snapshot)
classmethod
#
Restore a snapshot produced by :meth:snapshot_state.
Source code in jaqsi/pulses.py
set_envelope(name, rwa=None, frame=None)
classmethod
#
Switch pulse envelope and rebuild all PulseParams trees.
Also updates the coefficient functions used by :class:PulseGates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
One of :meth: |
required |
rwa
|
Optional[bool]
|
If given, also update the RWA flag. If |
None
|
frame
|
Optional[str]
|
If given, also update the coefficient frame
( |
None
|
Source code in jaqsi/pulses.py
set_frame(frame)
classmethod
#
Switch the algebraic representation of the (non-RWA) coefficients.
"lab" (default) and "drive" are mathematically
identical (no information lost, no RWA applied) — see
:meth:PulseEnvelope.build_coeff_fns for when "drive" is
useful. Rebuilds the coefficient functions for the currently
active envelope so the change takes effect immediately.
Source code in jaqsi/pulses.py
set_rwa(rwa)
classmethod
#
Toggle the rotating-wave approximation for pulse coefficients.
Rebuilds the coefficient functions for the currently active
envelope so the change takes effect immediately. Default is
False (exact interaction picture).
See :meth:PulseEnvelope.build_coeff_fns for details
Source code in jaqsi/pulses.py
snapshot_state()
classmethod
#
Return an immutable snapshot of the active pulse configuration.
Source code in jaqsi/pulses.py
update_params(path=None)
classmethod
#
Load QOC-tuned pulse parameters for the active envelope.
Defaults to the qoc_results_<envelope>.csv shipped with the
package; pass path to load a file produced by a custom QOC run.
Source code in jaqsi/pulses.py
Operations#
Base class for any quantum operation or observable.
Further gates should inherit from this class to realise more specific
operations. Generally, operations are created by instantiation inside a
circuit function passed to :class:Script; the instance is
automatically appended to the active tape.
An Operation can also serve as an observable: its matrix is used to
compute expectation values via apply_to_state / apply_to_density.
Attributes:
| Name | Type | Description |
|---|---|---|
_matrix |
ndarray
|
Class-level default gate matrix. Subclasses set this to their
fixed unitary. Instances may override it via the matrix argument
to |
_num_wires |
Optional[int]
|
Expected number of wires for this gate. Subclasses set
this to enforce wire count validation. |
_param_names |
Tuple[str, ...]
|
Tuple of attribute names for the gate parameters.
Used by :attr: |
Source code in jaqsi/operations.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
matrix
property
#
Return the base matrix of this operation (before lifting).
Returns:
| Type | Description |
|---|---|
ndarray
|
The gate matrix as a JAX array. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the subclass has not defined |
parameters
property
#
Return the list of numeric parameters for this operation.
Uses the declarative _param_names tuple to collect parameter
values in a canonical order. Non-parametrized gates return an
empty list.
Returns:
| Type | Description |
|---|---|
list
|
List of parameter values (floats or JAX arrays). |
wires
property
writable
#
Qubit indices this operation acts on.
Returns:
| Type | Description |
|---|---|
List[int]
|
List of integer qubit indices. |
__add__(other)
#
Element-wise addition of two operations on the same wires.
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the wire sets differ. |
Source code in jaqsi/operations.py
__init__(wires=0, matrix=None, record=True, name=None)
#
Initialise the operation and optionally register it on the active tape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Qubit index or list of qubit indices this operation acts on. |
0
|
matrix
|
Optional[ndarray]
|
Optional explicit gate matrix. When provided it overrides
the class-level |
None
|
record
|
bool
|
If |
True
|
name
|
Optional[str]
|
Optional explicit name for this operation. When |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in jaqsi/operations.py
__matmul__(other)
#
Tensor (Kronecker) product or matrix product of two operations.
The resulting operation acts on the union of both wire sets. If the wire sets are disjoint, this is a Kronecker product. If the wire sets overlap, the corresponding matrices are multiplied.
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Operation
|
operation on the unified wire set. |
Source code in jaqsi/operations.py
__mul__(other)
#
Return a new operation, the product between U and a scalar (U*x)
or the composition of two operations.
Usage inside a circuit function::
PauliX(wires=0) * x
PauliX(wires=0) * PauliZ(wires=0)
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Operation
|
or the composed matrix acting on the appropriate wires. |
Source code in jaqsi/operations.py
__repr__()
#
Return a human-readable representation of this operation.
Returns:
| Type | Description |
|---|---|
str
|
A string like |
Source code in jaqsi/operations.py
apply_to_density(rho, n_qubits)
#
Apply this gate to a density matrix via \rho -> U\rho U\dagger.
The density matrix (shape (2**n, 2**n)) is treated as a rank-2n
tensor with n "ket" axes (0..n-1) and n "bra" axes (n..2n-1).
U acts on the ket half; U* acts on the bra half. Both contractions
use the shared :func:_contract_and_restore helper, keeping the
operation allocation-free with respect to building full unitaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
ndarray
|
Density matrix of shape |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Updated density matrix of shape |
Source code in jaqsi/operations.py
apply_to_state(state, n_qubits)
#
Apply this gate to a statevector via tensor contraction.
The statevector (shape (2**n,)) is reshaped into a rank-n tensor
of shape (2,)*n. The gate (shape (2**k, 2**k)) is reshaped to
(2,)*2k and contracted against the k target wire axes.
Memory footprint is O(2**n) and the operation supports arbitrary k. The implementation is fully differentiable through JAX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ndarray
|
Statevector of shape |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Updated statevector of shape |
Source code in jaqsi/operations.py
apply_to_state_tensor(psi, n_qubits)
#
Apply this gate to a statevector already in tensor form.
Like :meth:apply_to_state but expects the state in rank-n tensor
form (2,)*n and returns the result in the same form. This avoids
the reshape calls at the per-gate level when the simulation loop
keeps the state in tensor form throughout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi
|
ndarray
|
Statevector tensor of shape |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Updated statevector tensor of shape |
Source code in jaqsi/operations.py
dagger()
#
Return a new operation, the conjugate transpose (U\dagger)
Usage inside a circuit function::
RX(0.5, wires=0).dagger()
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Source code in jaqsi/operations.py
decompose()
#
Decompose this operation into a list of more primitive operations.
The returned operations are created with record=False so the caller
controls where they are placed. Used e.g. by Pauli-Clifford transforms to
express composite gates in terms of Clifford + Pauli-rotation primitives.
Returns:
| Type | Description |
|---|---|
List[Operation]
|
List of :class: |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the gate has no decomposition (it is itself primitive). |
Source code in jaqsi/operations.py
lifted_matrix(n_qubits)
#
Return the full 2**n x 2**n matrix embedding this gate.
Embeds the k-qubit gate matrix into the n-qubit Hilbert space
by applying it to the identity matrix via :meth:apply_to_state.
This is useful for computing Tr(O·\rho ) directly without vmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The |
Source code in jaqsi/operations.py
power(power)
#
Return a new operation, the power (U^power)
Usage inside a circuit function::
PauliX(wires=0).power(2)
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Source code in jaqsi/operations.py
prod(*ops)
#
Construct the generalized product (tensor or matrix) of this operation with others.
The resulting operation acts on the union of all wire sets. If the wire sets are disjoint, this is a Kronecker product. If the wire sets overlap, the corresponding matrices are multiplied.
Usage::
res = op1.prod(op2, op3)
# or
res = Operation.prod(op1, op2, op3)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*ops
|
Operation
|
Variable number of :class: |
()
|
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Source code in jaqsi/operations.py
Hermitian#
Bases: Operation
A generic Hermitian observable or gate defined by an arbitrary matrix.
Example
obs = Hermitian(matrix=my_matrix, wires=0)
Source code in jaqsi/operations.py
__init__(matrix, wires=0, record=True)
#
Initialise a Hermitian operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
The Hermitian matrix defining this operator. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or list of qubit indices this operator acts on. |
0
|
record
|
bool
|
If |
True
|
Source code in jaqsi/operations.py
__rmul__(coeff_fn)
#
Support coeff_fn * Hermitian -> :class:ParametrizedHamiltonian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeff_fn
|
Callable
|
A callable |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ParametrizedHamiltonian |
ParametrizedHamiltonian
|
A :class: |
Raises:
| Type | Description |
|---|---|
TypeError
|
If coeff_fn is not callable. |
Source code in jaqsi/operations.py
evolve(name=None, **odeint_kwargs)
#
Return a gate factory for static evolution U = exp(-i t H).
Thin delegator to :meth:jaqsi.evolution.Evolution.evolve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional[str]
|
Optional name for the produced :class: |
None
|
**odeint_kwargs
|
Unused for static evolution (accepted for a
uniform signature with :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Callable
|
A callable gate factory |
Source code in jaqsi/operations.py
Parametrized Hamiltonian#
A time-dependent Hamiltonian as a sum of coeff * Hermitian terms.
Mathematically::
H(t) = \sum_i f_i(params_i, t) * H_i
Construction is always done from an explicit list of
(coeff_fn, H_mat, wires) triples passed as terms. The
common single-term shorthand is the operator form
coeff_fn * Hermitian(matrix, wires) (see
:meth:Hermitian.__rmul__), which returns a one-term instance.
Multi-term Hamiltonians are composed with + between
:class:ParametrizedHamiltonian instances::
H1 = coeff_x * Hermitian(X, wires=0)
H2 = coeff_y * Hermitian(Y, wires=0)
H_td = H1 + H2
# evolve under the composite Hamiltonian; coeff_args is a list of
# parameter sets, one per term, in the order the terms were added:
H_td.evolve()([px, py], T=1.0)
Attributes:
| Name | Type | Description |
|---|---|---|
coeff_fns |
Tuple[Callable, ...]
|
Tuple of callables |
H_mats |
Tuple[ndarray, ...]
|
Tuple of static Hermitian matrices, one per term. |
wires |
List[int]
|
Wires this Hamiltonian acts on (union across all terms; for now all terms are required to share the same wire set). |
Source code in jaqsi/operations.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 | |
H_mats
property
#
Tuple of Hermitian matrices, one per term.
coeff_fns
property
#
Tuple of coefficient functions, one per term.
n_terms
property
#
Number of terms in the Hamiltonian.
__add__(other)
#
Concatenate term lists: H = H1 + H2.
Source code in jaqsi/operations.py
__init__(terms)
#
Build a (possibly multi-term) parametrized Hamiltonian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terms
|
List[Tuple[Callable, ndarray, Union[int, List[int]]]]
|
List of |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the term list is empty, or if terms act on
differing wire sets (multi-wire broadcasting is
deferred — see :mod: |
Source code in jaqsi/operations.py
__neg__()
#
Negate every coefficient: -H = sum of (-f_i) * H_i.
Source code in jaqsi/operations.py
evolve(name=None, **odeint_kwargs)
#
Return a gate factory for time-dependent evolution.
Solves dU/dt = -i [sum_i f_i(p_i, t) H_i] U. Thin delegator to
:meth:jaqsi.evolution.Evolution.evolve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional[str]
|
Optional name for the produced :class: |
None
|
**odeint_kwargs
|
Solver options forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Callable
|
A callable gate factory |
Source code in jaqsi/operations.py
Pauli Rotation#
Bases: Operation
Multi-qubit Pauli rotation: exp(-i \theta/2 P) for a Pauli word P.
The Pauli word is given as a string of 'I', 'X', 'Y', 'Z'
characters (one per qubit). The rotation matrix is computed as
cos(\theta/2) I - i sin(\theta/2) P where P is the tensor product of the
corresponding single-qubit Pauli matrices.
Example::
PauliRot(0.5, "XY", wires=[0, 1])
Source code in jaqsi/gateset.py
__init__(theta, pauli_word, wires=0, **kwargs)
#
Initialise a PauliRot gate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
Rotation angle in radians. |
required |
pauli_word
|
str
|
A string of |
required |
wires
|
Union[int, List[int]]
|
Qubit index or list of qubit indices this gate acts on. |
0
|
Source code in jaqsi/gateset.py
generator()
#
Return the generator Pauli tensor product as an :class:Operation.
The generator of PauliRot(\theta, word, wires) is the tensor product
of single-qubit Pauli matrices specified by word. The returned
:class:Hermitian wraps that matrix and the gate's wires.
Returns:
| Type | Description |
|---|---|
Operation
|
class: |
Source code in jaqsi/gateset.py
Paulis#
Symbolic n-qubit Pauli operator in the stabilizer-tableau (symplectic) representation.
A Pauli word is stored as
.. math:: P = i^{\text{phase}} \prod_{q} X_q^{x_q} Z_q^{z_q},
with bit arrays x, z \in \{0, 1\}^n and an integer phase taken mod 4
(tracking the scalar i^{phase}). Single-qubit Paulis map as
I=(0,0), X=(1,0), Z=(0,1), Y=(1,1) (since Y = i X Z).
This replaces the matrix-based Clifford conjugation
(:func:evolve_pauli_with_clifford + :func:pauli_decompose) with O(n)
symbolic updates, and backs Pauli-Clifford circuit transforms and
Fourier-tree algorithms built on top of it.
All operations use NumPy (integer arithmetic), not JAX — this is symbolic bookkeeping, not numeric computation.
Source code in jaqsi/paulis.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
is_diagonal
property
#
Whether the word is diagonal (only I/Z, i.e. no X component).
n_qubits
property
#
Number of qubits this Pauli word spans.
xy_mask
property
#
Boolean mask of qubits carrying an X or Y (i.e. x bits set).
__init__(x, z, phase=0)
#
Initialise a Pauli word.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Integer/boolean array of X-component bits, length |
required |
z
|
ndarray
|
Integer/boolean array of Z-component bits, length |
required |
phase
|
int
|
Exponent of the global |
0
|
Source code in jaqsi/paulis.py
commutes_with(other)
#
Return whether this Pauli word commutes with other.
Two Paulis commute iff their symplectic inner product vanishes mod 2.
Source code in jaqsi/paulis.py
compose(other)
#
Return the operator product self @ other as a new Pauli word.
Uses the exact symplectic product rule
.. math:: (X^{x_1} Z^{z_1})(X^{x_2} Z^{z_2}) = (-1)^{z_1 \cdot x_2}\, X^{x_1 \oplus x_2} Z^{z_1 \oplus z_2},
combined with the i^{phase} scalars (-1 = i^2).
Source code in jaqsi/paulis.py
conjugate_by_clifford(clifford, adjoint_left=False)
#
Return the Clifford conjugation of this Pauli word.
Computes C P C^\dagger (adjoint_left=False) or
C^\dagger P C (adjoint_left=True) symbolically, where C is one
of the supported Clifford gates H, S, CX, CZ or a Pauli gate
PauliX/PauliY/PauliZ.
The conjugation is realised by substituting the images of the
single-qubit generators X_q and Z_q and re-composing in canonical
order, so all phases are tracked exactly by :meth:compose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clifford
|
Operation
|
The Clifford operation to conjugate by. |
required |
adjoint_left
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
PauliWord
|
The conjugated :class: |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If clifford is not a supported gate. |
Source code in jaqsi/paulis.py
expectation(state)
#
Return \langle\psi|P|\psi\rangle for an arbitrary statevector.
Applies the single-qubit Pauli factors to the reshaped state via tensor
contraction (O(n 2^n)) instead of forming the dense
2^n \times 2^n operator. The real part is exact for a Hermitian
Pauli word.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ndarray
|
Statevector of length |
required |
Returns:
| Type | Description |
|---|---|
complex
|
The expectation value |
Source code in jaqsi/paulis.py
from_matrix(matrix)
classmethod
#
Build a Pauli word from a matrix that is a single (signed) Pauli.
Recovers the dominant Pauli string and folds its (unit) coefficient
c = i^k into the word's phase. Intended for matrices that are
exactly a Pauli up to a {\pm 1, \pm i} scalar (e.g. the result of
Clifford conjugation of a Pauli); the dominant term is returned for
general inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
A |
required |
Returns:
| Type | Description |
|---|---|
PauliWord
|
The corresponding :class: |
Source code in jaqsi/paulis.py
from_operation(op, n_qubits)
classmethod
#
Build a Pauli word from a Pauli-like operation.
Supports :class:PauliX/:class:PauliY/:class:PauliZ/:class:Id,
:class:PauliRot (via its pauli_word), and any operation carrying a
_pauli_label (e.g. produced by :func:pauli_decompose) or otherwise
decomposable by :func:pauli_string_from_operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
Operation
|
The operation to convert. |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
PauliWord
|
The corresponding :class: |
Source code in jaqsi/paulis.py
from_pauli_string(pauli_string, wires, n_qubits)
classmethod
#
Build a Pauli word from a Pauli string and its wires.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pauli_string
|
str
|
String over |
required |
wires
|
List[int]
|
Qubit indices the characters act on. |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
PauliWord
|
The corresponding :class: |
Source code in jaqsi/paulis.py
identity(n_qubits)
classmethod
#
leading_phase()
#
Return the scalar c such that P = c * (bare Pauli string).
Because the bare string already contains i^{n_Y} from its Y factors,
c = i^{phase - n_Y}.
Source code in jaqsi/paulis.py
to_list_repr()
#
Return the legacy int list representation (I=-1, X=0, Y=1, Z=2).
Source code in jaqsi/paulis.py
to_matrix()
#
Return the dense operator matrix i^{phase} \bigotimes_q X^{x_q} Z^{z_q}.
The per-qubit factor is the symplectic product X^{x} Z^{z} (so the
(1, 1) factor is XZ = -iY; the Y-vs-XZ phase is carried by
i^{phase}). Inverse of :meth:from_matrix.
Source code in jaqsi/paulis.py
to_pauli_string()
#
Return the bare Pauli string (ignoring the global phase).
to_pauli_string_and_phase()
#
zero_expectation()
#
Return <0|P|0> for the all-zero computational basis state.
Non-zero only for diagonal words (I/Z only), in which case it equals the
global phase i^{phase}.
Source code in jaqsi/paulis.py
Decompose a Hermitian matrix into a sum of Pauli tensor products.
For an n-qubit matrix (2**n x 2**n), returns the dominant Pauli
term (the one with the largest absolute coefficient), wrapped as an
:class:Operation. This is sufficient for the Fourier-tree algorithm
which only needs the single non-zero Pauli term produced by Clifford
conjugation of a Pauli operator.
The decomposition uses the trace formula:
c_P = Tr(P · M) / 2**n
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
A |
required |
wire_order
|
Optional[List[int]]
|
Optional list of wire indices. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
|
A tuple |
||
|
op is the Pauli :class: |
||
a |
class: |
Source code in jaqsi/paulis.py
Return \langle\psi|O|\psi\rangle for a Pauli observable and statevector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obs
|
Union[str, PauliWord]
|
The observable, either a :class: |
required |
state
|
ndarray
|
Statevector of length |
required |
Returns:
| Type | Description |
|---|---|
complex
|
The expectation value |
Source code in jaqsi/paulis.py
Noise#
Bases: Operation
Base class for noise channels defined by a set of Kraus operators.
A Kraus channel \phi(\rho ) = \sigma_k K_k \rho K_k\dagger is the most general physical operation on a quantum state. For a pure unitary gate there is a single operator K_0 = U satisfying K_0\daggerK_0 = I; for noisy channels there are multiple operators.
Subclasses must implement :meth:kraus_matrices and return a list of JAX
arrays. :meth:apply_to_state is intentionally left unimplemented:
Kraus channels require a density-matrix representation and cannot be
applied to a pure statevector in general.
Source code in jaqsi/noise.py
matrix
property
#
Raises TypeError — noise channels have no single unitary matrix.
Raises:
| Type | Description |
|---|---|
TypeError
|
Always raised; use :meth: |
apply_to_density(rho, n_qubits)
#
Apply \phi(\rho ) = \sigma_k K_k \rho K_k\dagger using tensor-contraction.
Uses the shared :func:_contract_and_restore helper, summing the
result over all Kraus operators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
ndarray
|
Density matrix of shape |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Updated density matrix of shape |
Source code in jaqsi/noise.py
apply_to_state(state, n_qubits)
#
Raises TypeError — noise channels require density-matrix simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ndarray
|
Statevector (unused). |
required |
n_qubits
|
int
|
Number of qubits (unused). |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
Always raised; use |
Source code in jaqsi/noise.py
apply_to_state_tensor(psi, n_qubits)
#
Raises TypeError — noise channels require density-matrix simulation.
Source code in jaqsi/noise.py
kraus_matrices()
#
Return the list of Kraus operators for this channel.
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
List of 2-D JAX arrays, each of shape |
List[ndarray]
|
is the number of target qubits. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Subclasses must override this method. |
Source code in jaqsi/noise.py
Bases: KrausChannel
Generic Kraus channel from a user-supplied list of Kraus operators.
This replaces PennyLane's qml.QubitChannel and accepts an arbitrary set
of Kraus matrices satisfying \sigma_k K_k\dagger K_k = I.
Example::
kraus_ops = [jnp.sqrt(0.9) * jnp.eye(2), jnp.sqrt(0.1) * PauliX._matrix]
QubitChannel(kraus_ops, wires=0)
Source code in jaqsi/noise.py
__init__(kraus_ops, wires=0)
#
Initialise a generic Kraus channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kraus_ops
|
List[ndarray]
|
List of Kraus matrices. Each must be a square 2D array
of dimension |
required |
wires
|
Union[int, List[int]]
|
Qubit index or list of qubit indices this channel acts on. |
0
|
Source code in jaqsi/noise.py
kraus_matrices()
#
Return the stored Kraus operators.
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
List of Kraus operator matrices. |
Math#
from jaqsi.math import quantum_fisher_information, fubini_study_metric, fidelity, trace_distance, phase_difference, partial_trace, marginalize_probs, logm_v
Compute the Quantum Fisher Information (QFI) at a parameter point.
The QFI is the metric tensor of the state manifold evaluated at
params. It therefore requires the state as a function of the
parameters rather than a single state; the Jacobian is obtained with
forward-mode automatic differentiation (:func:jax.jacfwd), which yields
the complex Jacobian directly for real-valued parameters.
Both pure and mixed states are supported and dispatched on the kind of
object returned by state_fn (state vector vs. density matrix), mirroring
:func:fidelity:
- state vector of shape
(d,)-> Fubini-Study formula (see :func:_qfi_statevector), - density matrix of shape
(d, d)-> symmetric logarithmic derivative formula (see :func:_qfi_density).
The returned matrix has shape (P, P) where P is the total number of
parameters (the parameter axes of params are flattened).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_fn
|
Callable mapping params to a normalised quantum state.
Typically |
required | |
params
|
ndarray
|
Parameters at which the QFI is evaluated. Must be passed in the
shape expected by state_fn (e.g. the model's batched
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Real, symmetric QFI matrix of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If state_fn returns neither a state vector nor a square density matrix. |
Source code in jaqsi/math.py
Compute the Fubini-Study metric tensor at a parameter point.
The Fubini-Study metric is the real part of the quantum geometric tensor on
the manifold of pure states and equals the pure-state quantum Fisher
information up to a factor of four, :math:F_{ij} = 4\,g_{ij}:
.. math::
g_{ij} = \mathrm{Re}\left[
\braket{\partial_i\psi | \partial_j\psi}
- \braket{\partial_i\psi | \psi}\braket{\psi | \partial_j\psi}
\right]
It is only defined for pure states; state_fn must therefore return a
normalised state vector. See :func:quantum_fisher_information for the
calling convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_fn
|
Callable mapping params to a normalised state vector.
Typically |
required | |
params
|
ndarray
|
Parameters at which the metric is evaluated. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Real, symmetric metric of shape |
ndarray
|
number of parameters. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If state_fn does not return a state vector. |
Source code in jaqsi/math.py
Compute the fidelity between two quantum states.
Accepts either state vectors or density matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state0
|
ndarray
|
State vector or density matrix. |
required |
state1
|
ndarray
|
State vector or density matrix (same kind as state0). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Fidelity (scalar or shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the two states have incompatible shapes or different representations (vector vs. matrix). |
Source code in jaqsi/math.py
Compute the trace distance between two quantum states.
Supports single density matrices of shape (2**N, 2**N) and batched
density matrices of shape (B, 2**N, 2**N).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state0
|
ndarray
|
Density matrix of shape |
required |
state1
|
ndarray
|
Density matrix of shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Trace distance (scalar or shape |
Source code in jaqsi/math.py
Compute the phase difference between two state vectors.
A value of zero indicates the two states are related by at most a
real global factor (i.e. no relative phase). The result lies in
:math:[-\pi, 1 + \pi].
Supports single state vectors of shape (2**N,) and batched state
vectors of shape (B, 2**N).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state0
|
ndarray
|
State vector of shape |
required |
state1
|
ndarray
|
State vector of shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Phase difference (scalar or shape |
Source code in jaqsi/math.py
Partial trace of a density matrix, keeping only the specified qubits.
Supports both single density matrices of shape (2**n, 2**n) and
batched density matrices of shape (B, 2**n, 2**n).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
ndarray
|
Density matrix of shape |
required |
n_qubits
|
int
|
Total number of qubits. |
required |
keep
|
List[int]
|
List of qubit indices to keep (0-indexed). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Reduced density matrix of shape |
ndarray
|
where k = |
Source code in jaqsi/math.py
Marginalize a probability vector to keep only the specified qubits.
Supports both single probability vectors of shape (2**n,) and
batched vectors of shape (B, 2**n).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probs
|
ndarray
|
Probability vector of shape |
required |
n_qubits
|
int
|
Total number of qubits. |
required |
keep
|
Tuple[int]
|
List of qubit indices to keep (0-indexed). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Marginalized probability vector of shape |
ndarray
|
where k = |
Source code in jaqsi/math.py
Compute the logarithm of a matrix. If the provided matrix has an additional batch dimension, the logarithm of each matrix is computed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray
|
The (potentially batched) matrices of which to compute |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: The log matrices |
Source code in jaqsi/math.py
Quantum Optimal Control#
Quantum Optimal Control for pulse-level gate synthesis.
Optimises pulse parameters to reproduce the unitary of standard quantum gates using a two-stage strategy.
Attributes:
| Name | Type | Description |
|---|---|---|
GATES_1Q |
List[str]
|
Names of supported single-qubit gates. |
GATES_2Q |
List[str]
|
Names of supported two-qubit gates. |
DEFAULT_PARAM_RANGES |
Default parameter ranges for each gate. |
Source code in jaqsi/qoc.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 | |
__init__(envelope, cost_fns, t_target, n_steps, n_samples, learning_rate, log_interval=50, file_dir=None, warmup_ratio=0.0, end_lr_ratio=1.0, n_restarts=1, restart_noise_scale=0.5, grad_clip=1.0, random_seed=42, scan_steps=0, scan_grid_size=5, scan_ranges=None, log_scale_params=None, early_stop_patience=0, early_stop_min_delta=0.0, plot=False)
#
Initialize Quantum Optimal Control with Pulse-level Gates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
envelope
|
str
|
Pulse envelope shape to use for optimization. Must be one of the registered envelopes in PulseEnvelope (e.g. 'gaussian', 'square', 'cosine', 'drag', 'sech'). |
required |
cost_fns
|
list
|
List of |
required |
t_target
|
float
|
Target evolution time for the
|
required |
n_steps
|
int
|
Number of steps in optimization. |
required |
n_samples
|
int
|
Number of parameter samples per step. |
required |
learning_rate
|
float
|
Peak learning rate for AdamW. When a warmup/decay schedule is active this is the maximum LR reached after the warmup phase. |
required |
log_interval
|
int
|
Interval for logging. |
50
|
file_dir
|
str
|
Directory to save results. |
None
|
warmup_ratio
|
float
|
Fraction of |
0.0
|
end_lr_ratio
|
float
|
The final learning rate is
|
1.0
|
n_restarts
|
int
|
Number of random restarts for the optimisation. The first run uses the initial parameters as-is; subsequent runs add scaled random perturbations. The best result across all restarts is kept. Set to 1 to disable restarts (default behaviour). |
1
|
restart_noise_scale
|
float
|
Standard deviation of the
Gaussian noise added to the initial parameters for each
restart (relative to the absolute value of each parameter).
Defaults to 0.5 (50 % relative perturbation). Note that
the package-level default in |
0.5
|
grad_clip
|
float
|
Maximum global gradient norm. Gradients
are clipped to this value before being passed to the
optimiser, which stabilises training when the loss
landscape has steep regions. Set to |
1.0
|
random_seed
|
int
|
Base random seed for generating restart perturbations. Defaults to 42. |
42
|
scan_steps
|
int
|
Number of short gradient-descent steps to run for each candidate in the coarse grid search (Stage 0). Set to 0 to disable the grid scan entirely and rely solely on restarts. A value of 20-50 is usually enough to identify promising basins. Defaults to 0. |
0
|
scan_grid_size
|
int
|
Number of points per parameter
dimension in the coarse grid. The total number of
candidates is |
5
|
scan_ranges
|
Optional[List[Tuple[float, float]]]
|
Per-
parameter |
None
|
log_scale_params
|
Optional[List[int]]
|
Indices of pulse
parameters that should be optimised in log-space. For
these parameters the optimizer sees |
None
|
early_stop_patience
|
int
|
Number of consecutive
Stage-1 steps with no improvement greater than
|
0
|
early_stop_min_delta
|
float
|
Minimum decrease in loss
that counts as an improvement for the early-stopping
patience counter. Defaults to |
0.0
|
plot
|
bool
|
If |
False
|
Source code in jaqsi/qoc.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
create_CPhase()
#
Create pulse and target circuits for the CPhase gate.
Source code in jaqsi/qoc.py
optimize(wires)
#
Decorator factory that optimises pulse parameters for a gate.
Usage::
opt = qoc.optimize(wires=1)
best_params, loss_history = opt(qoc.create_RX)()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
int
|
Number of qubits the gate acts on. |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
A decorator that accepts a circuit-factory function and |
Callable
|
returns a callable ``(init_pulse_params=None) -> |
Callable
|
(best_params, loss_history)``. |
Source code in jaqsi/qoc.py
1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 | |
optimize_all(sel_gates, make_log)
#
Optimise all selected gates and optionally write a log CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sel_gates
|
str
|
Comma-separated gate names or |
required |
make_log
|
bool
|
If |
required |
Source code in jaqsi/qoc.py
optimize_joint(target_gates=None, leaf_names=None, weights=None)
#
Joint composite-aware optimisation of leaf pulse parameters.
Optimises a single shared parameter vector theta (containing
the concatenated leaf params for leaf_names) against a
weighted sum of unitary-cost terms over target_gates.
Composite gates back-propagate into the shared leaves; leaf
terms keep the standalone fidelity acceptable. CZ is omitted
from the default targets because the PulseGates.CZ
implementation is a static diagonal-Hamiltonian evolution
(H_CZ = π·|11⟩⟨11|, t=1) that is structurally exact and
unaffected by any leaf re-tuning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_gates
|
Optional[List[str]]
|
Gates whose unitary cost contributes to the
joint objective. Defaults to
:pyattr: |
None
|
leaf_names
|
Optional[List[str]]
|
Leaf gates whose parameters are jointly
optimised. Defaults to :pyattr: |
None
|
weights
|
Optional[Dict[str, float]]
|
Optional mapping |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ndarray
|
|
|
Dict[str, slice]
|
results are also written to |
|
via |
list
|
meth: |
Source code in jaqsi/qoc.py
2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 | |
plot_loss_curve(gate_name, loss_history)
#
Save a training-loss curve figure for the Phase-1 optimisation.
Shows loss vs. optimisation step on a log y-scale with a dashed horizontal line at the minimum achieved loss.
The figure is saved to {file_dir}/{gate_name}_loss_curve.png.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate_name
|
str
|
Name of the gate being optimised (e.g. |
required |
loss_history
|
list
|
Sequence of loss values, one per step (including the initial loss at index 0). |
required |
Source code in jaqsi/qoc.py
plot_loss_landscape(gate_name, grid_axes, landscape_data)
#
Save a loss-landscape figure for the Phase-0 grid scan.
The visualisation adapts to the number of pulse parameters:
- 1 parameter: line/scatter plot (param value vs. loss).
- 2 parameters: 2-D heatmap (param₀ × param₁, colour = loss).
- ≥ 3 parameters: horizontal scatter sorted by ascending loss with the best candidate highlighted.
The figure is saved to {file_dir}/{gate_name}_loss_landscape.png.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate_name
|
str
|
Name of the gate being optimised (e.g. |
required |
grid_axes
|
List[ndarray]
|
Per-parameter 1-D arrays that span the scan grid. |
required |
landscape_data
|
list
|
List of |
required |
Source code in jaqsi/qoc.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 | |
save_results(gate, fidelity, pulse_params)
#
Save optimised pulse parameters and fidelity for a gate to CSV.
If the gate already exists in the file, its entry is overwritten regardless of whether the new fidelity is higher. A warning is logged when the existing fidelity was better.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate
|
str
|
Name of the gate (e.g. |
required |
fidelity
|
float
|
Achieved fidelity of the optimised pulse. |
required |
pulse_params
|
ndarray
|
Optimised pulse parameters for the gate. |
required |
Source code in jaqsi/qoc.py
stage_0_opt(init_pulse_params, total_cost)
#
Run the coarse grid-scan phase (Stage 0).
Evaluates a Cartesian grid of parameter candidates using the full weighted cost (fidelity + phase, plus any other registered terms) — the same objective as Stage 1. Each candidate is refined with a few fast gradient steps. Returns the best-found parameters.
Sharing the objective with Stage 1 prevents the grid scan from landing in a basin that has high fidelity but a biased phase which Adam then has to migrate out of (the previous fidelity-only scan caused exactly this failure mode for RX/RY, whose phase residuals compounded in the CRX decomposition).
Robustness: candidates that produce a non-finite loss (e.g. when
the underlying pulse drives the integrator into a NaN — typical
for very narrow DRAG envelopes) are skipped with a warning. For
the duration of the scan, :class:jaqsi.evolution.Evolution is
switched into throw=False mode so a single bad candidate
cannot abort the loop with MaxStepsReached; the previous
defaults are restored on exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_pulse_params
|
ndarray
|
Initial pulse parameters to compare against. |
required |
total_cost
|
Callable
|
Combined cost callable (same as Stage 1). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of: |
Optional[Tuple[List[ndarray], list]]
|
|
Tuple[ndarray, Optional[Tuple[List[ndarray], list]]]
|
|
Source code in jaqsi/qoc.py
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
stage_1_opt(best_scan_params, total_costs)
#
Run multi-restart gradient optimisation (Stage 1).
Performs n_restarts independent AdamW runs with the full
(weighted) cost function. The first restart uses
best_scan_params directly; subsequent restarts add random
perturbations. Parameters specified in log_scale_params are
optimised in log-space.
When n_restarts == 1 we keep the original single-restart
Python loop (it preserves per-step log.info granularity
and avoids the vmap/scan compilation overhead). When
n_restarts > 1 we vmap the optimiser over restarts and
run the inner step loop with :func:jax.lax.scan, fusing all
n_restarts × n_steps steps into a single XLA program.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_scan_params
|
ndarray
|
Starting parameters (typically from Stage 0). |
required |
total_costs
|
Callable
|
Combined cost callable. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of |
list
|
best restart. |
Source code in jaqsi/qoc.py
Cost Functions#
Weighted wrapper around a cost function.
Combines a cost callable with a scalar or tuple weight and optional
constant keyword arguments. Multiple Cost instances can be
composed via the + operator to build a combined objective.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost
|
Callable
|
Callable |
required |
weight
|
Union[float, Tuple]
|
Scalar or tuple of per-component weights. |
required |
ckwargs
|
Optional[dict]
|
Constant keyword arguments injected into every call. |
None
|
Source code in jaqsi/qoc.py
__add__(other)
#
Compose two cost terms into a single callable that sums them.
Source code in jaqsi/qoc.py
__call__(*args, **kwargs)
#
Evaluate the cost function with injected kwargs and apply weights.
Source code in jaqsi/qoc.py
Cost Function Registry#
Registry of cost functions available for pulse optimisation.
Use :meth:register to add new cost functions at runtime and
:meth:get / :meth:available to query them.
Source code in jaqsi/qoc.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
available()
classmethod
#
get(name)
classmethod
#
Look up cost-function metadata by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registered cost function name. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Metadata dict with keys |
dict
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not registered. |
Source code in jaqsi/qoc.py
parse_cost_arg(spec)
classmethod
#
Parse a "name:w1,w2,..." CLI string into (name, weight).
If a tuple is provided, it is returned directly.
If the weight part is omitted the default weight from the registry is used. A single-component weight is returned as a float; multi-component weights are returned as a tuple of floats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Union[str, Tuple]
|
A string of the form |
required |
Returns:
| Type | Description |
|---|---|
Tuple[str, Union[float, Tuple[float, ...]]]
|
A tuple of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the name is unknown or the number of weight
components does not match the ones in |
Source code in jaqsi/qoc.py
Evolution Engine#
Source code in jaqsi/evolution.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
clear_evolve_solver_cache()
classmethod
#
Drop every cached compiled evolve solver.
Call this whenever the coefficient functions referenced by the
cache keys are rebuilt (e.g. when :class:PulseGates swaps in
a new pulse envelope, RWA flag or frame). Without an explicit
eviction the cache keeps the old code objects alive and would
also retain XLA programs that no longer match any active
coefficient function.
Source code in jaqsi/evolution.py
evolve(hamiltonian, name=None, **odeint_kwargs)
classmethod
#
Return a gate-factory for Hamiltonian time evolution.
Engine for the :meth:Hermitian.evolve / :meth:ParametrizedHamiltonian.evolve
methods (the usual entry point); it dispatches on the Hamiltonian type.
Supports two modes:
Static — when hamiltonian is a :class:Hermitian::
gate = Hermitian(H_mat, wires=0).evolve()
gate(t=0.5) # U = exp(-i*0.5*H)
Time-dependent — when hamiltonian is a
:class:ParametrizedHamiltonian (created via coeff_fn * Hermitian)::
H_td = coeff_fn * Hermitian(H_mat, wires=0)
gate = H_td.evolve()
gate([A, sigma], T) # U via ODE: dU/dt = -i f(p,t) H * U
The time-dependent case solves the Schrödinger equation numerically
using diffrax.diffeqsolve with a Dopri8 adaptive Runge-Kutta
solver
All computations are pure JAX and fully differentiable with
jax.grad.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hamiltonian
|
Union[Hermitian, ParametrizedHamiltonian]
|
Either a :class: |
required |
**odeint_kwargs
|
Any
|
Extra keyword arguments. Recognised keys:
|
{}
|
Returns:
| Type | Description |
|---|---|
Callable
|
A callable gate factory. Signature depends on the mode: |
Callable
|
|
Callable
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If hamiltonian is neither |
Source code in jaqsi/evolution.py
set_solver_defaults(max_steps=None, throw=None, solver=None, magnus_steps=None)
classmethod
#
Update class-level solver defaults; return the previous values.
The returned dictionary is suitable for restoring the previous
defaults via set_solver_defaults(**prev).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_steps
|
Optional[int]
|
New default for |
None
|
throw
|
Optional[bool]
|
New default for |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with the previous values of the updated keys. |
Source code in jaqsi/evolution.py
Script#
Circuit container and executor backed by pure JAX kernels.
Script takes a callable f representing a quantum circuit.
Within f, :class:~jaqsi.operations.Operation objects are
instantiated and automatically recorded onto a tape. The tape is then
simulated using either a statevector or density-matrix kernel depending on
whether noise channels are present.
The stateless simulation/measurement kernels live in
:mod:jaqsi.simulation and the memory-estimation/chunking helpers
in :mod:jaqsi.memory; this class orchestrates recording,
batching, caching, and drawing around them.
Attributes:
| Name | Type | Description |
|---|---|---|
f |
The circuit function whose body instantiates |
|
_n_qubits |
Optionally pre-declared number of qubits. When |
Example
def circuit(theta): ... RX(theta, wires=0) ... PauliZ(wires=1) script = Script(circuit, n_qubits=2) result = script.execute(type="expval", obs=[PauliZ(0)])
Source code in jaqsi/script.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 | |
__init__(f, n_qubits=None)
#
Initialise a Script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[..., None]
|
A function whose body instantiates |
required |
n_qubits
|
Optional[int]
|
Number of qubits. If |
None
|
Source code in jaqsi/script.py
draw(figure='text', args=(), kwargs=None, **draw_kwargs)
#
Draw the quantum circuit.
Records the tape by calling the circuit function with the given arguments, then renders the resulting gate sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figure
|
str
|
Rendering backend. One of:
|
'text'
|
args
|
tuple
|
Positional arguments forwarded to the circuit function to record the tape. |
()
|
kwargs
|
Optional[dict]
|
Keyword arguments forwarded to the circuit function. |
None
|
**draw_kwargs
|
Any
|
Extra options forwarded to the rendering backend:
|
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, Any]
|
Depends on figure: |
Union[str, Any]
|
|
Union[str, Any]
|
|
Union[str, Any]
|
|
Union[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If figure is not one of the supported modes. |
Source code in jaqsi/script.py
execute(type='expval', obs=None, *, args=(), kwargs=None, in_axes=None, shots=None, key=None, initial_state=None, fingerprint=None)
#
Execute the circuit and return measurement results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
Measurement type. One of:
|
'expval'
|
obs
|
Optional[List[Operation]]
|
Observables required when type is |
None
|
args
|
tuple
|
Positional arguments forwarded to the circuit function f. |
()
|
kwargs
|
Optional[dict]
|
Keyword arguments forwarded to f. |
None
|
in_axes
|
Optional[Tuple]
|
Batch axes for each element of args, following the same
convention as
When provided, :meth: |
None
|
shots
|
Optional[int]
|
Number of measurement shots for stochastic sampling.
If |
None
|
key
|
Optional[ndarray]
|
JAX PRNG key for shot sampling. If |
None
|
initial_state
|
Optional[ndarray]
|
Optional statevector to start the simulation from
instead of |00…0⟩. Without in_axes it must be a 1D state of
shape |
None
|
fingerprint
|
Optional[Hashable]
|
Hashable summary of any circuit-function state that is read while recording the tape but does not appear in args or kwargs. It takes part in the batched plan cache key, so a caller whose circuit structure depends on mutable external state (e.g. attributes of a model object wrapping this script) does not silently reuse a plan compiled for the previous structure. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Without in_axes: shape determined by type. |
ndarray
|
With in_axes: shape |
Source code in jaqsi/script.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
pulse_events(*args, **kwargs)
#
Run the circuit and collect pulse events emitted by PulseGates.
Activates both the normal operation tape (so gates execute) and
a pulse-event tape that captures
:class:~jaqsi.drawing.PulseEvent objects from leaf
pulse gates (RX, RY, RZ, CZ).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Forwarded to the circuit function. |
()
|
**kwargs
|
Any
|
Forwarded to the circuit function. |
{}
|
Returns:
| Type | Description |
|---|---|
list
|
List of :class: |
Source code in jaqsi/script.py
record(*args, **kwargs)
#
Run the circuit function and collect the recorded operations.
Uses :func:~jaqsi.tape.recording as a context manager so
that the tape is always cleaned up — even if the circuit function
raises — and nested recordings (e.g. from _execute_batched) each
get their own independent tape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Positional arguments forwarded to the circuit function. |
()
|
|
**kwargs
|
Keyword arguments forwarded to the circuit function. |
{}
|
Returns:
| Type | Description |
|---|---|
List[Operation]
|
List of :class: |
List[Operation]
|
the order they were instantiated. |
Source code in jaqsi/script.py
Drawing#
Wrapper around a quantikz LaTeX string with export helpers.
Source code in jaqsi/drawing.py
export(destination, full_document=False, mode='w')
#
Export a LaTeX document with a quantum circuit in stick notation.
Parameters#
quantikz_strs : str or list[str] LaTeX string for the quantum circuit or a list of LaTeX strings. destination : str Path to the destination file.
Source code in jaqsi/drawing.py
wrap_figure()
#
Wraps the quantikz string in a LaTeX figure environment.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A formatted LaTeX string representing the TikZ figure containing |
str
|
the quantum circuit diagram. |
Source code in jaqsi/drawing.py
Single pulse applied to one or more wires.
Attributes:
| Name | Type | Description |
|---|---|---|
gate |
str
|
Gate label, e.g. |
wires |
List[int]
|
Target qubit wire(s). |
envelope_fn |
Any
|
Pure envelope function |
envelope_params |
Any
|
Envelope-shape parameters (excluding |
w |
float
|
Rotation angle passed to the gate. |
duration |
float
|
Pulse duration (evolution time). |
carrier_phase |
float
|
Phase offset for the carrier cosine. |
parent |
Optional[str]
|
Optional high-level gate name that decomposed into this event. |
Source code in jaqsi/drawing.py
Tape#
Context manager that creates a fresh tape for recording operations.
Operations instantiated inside this block will be appended to the
returned tape list (via :func:active_tape). Nesting is supported:
each with recording() pushes a new tape onto the per-thread stack,
and the previous tape is restored on exit.
Yields:
| Type | Description |
|---|---|
List['Operation']
|
A new empty list that will be populated with |
Source code in jaqsi/tape.py
Context manager that collects pulse events emitted by PulseGates.
Yields:
| Type | Description |
|---|---|
list
|
A list that will be populated with |
list
|
class: |