Digital Twin Synchronization¶
Time-warp optimistic simulation for SC digital twins. Includes null-message lookahead, delta checkpointing, replay verification, drift auto-correction, and multi-twin federation with global virtual time.
Quick Start¶
from sc_neurocore.digital_twin.twinsync import (
TwinSession, NullMessageOptimizer, DeltaCheckpoint,
ReplayVerifier, DriftAutoCorrector, TwinFederation,
)
sc_neurocore.digital_twin.twinsync
¶
SC-native time-warp synchronization for BCI digital twins.
Provides causal ordering, checkpoint/resume, and time-warp rollback across distributed MPI nodes for real-time synchronization between a physical BCI subject and its billion-neuron SC digital twin.
Key primitives: - Lamport Clock: Logical timestamps for causal ordering - Vector Clock: Full causal dependency tracking across N nodes - Time-Warp Engine: Optimistic execution with anti-message rollback - Checkpoint Manager: Deterministic state snapshots with LFSR replay - Twin Session: Orchestrates physical ↔ digital synchronization
Architecture:
Physical BCI Subject
│ MEA / EEG / fNIRS
┌──────▼──────┐
│ SensorBridge │──► AER spike stream
└──────┬──────┘
│ causal-ordered events
┌──────▼──────────────────────────┐
│ TwinSync Time-Warp Engine │
│ ┌────────┐ ┌────────┐ ┌──────┐│
│ │ Node 0 │ │ Node 1 │ │Node N││
│ │ 100M │ │ 100M │ │100M ││
│ │neurons │ │neurons │ │neuro ││
│ └───┬────┘ └───┬────┘ └──┬───┘│
│ └──────────┴─────────┘ │
│ vector clocks │
└──────┬─────────────────────────┘
│ synchronized output
┌──────▼──────┐
│ OutputBridge │──► closed-loop stimulation
└─────────────┘
Compatible with:
- mpi_partitioner.py / hierarchical_partitioner.py — node topology
- identity substrate (ArcaneNeuron.v_deep) — preserved across rollback
- bioware/ — MEA/AER physical interface
- sc_scope/ — live monitoring of twin divergence
LamportClock
¶
Lamport logical clock for causal ordering.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
tick()
¶
Local event: increment.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
72 73 74 75 | |
send()
¶
Prepare timestamp for sending.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
77 78 79 80 | |
receive(remote_time)
¶
Update on message receipt.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
82 83 84 85 | |
VectorClock
¶
Vector clock for full causal dependency tracking.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
happened_before(other)
¶
Check if self happened-before other (self < other).
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
109 110 111 | |
concurrent_with(other)
¶
Check if self is concurrent with other.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
113 114 115 116 117 | |
TwinEvent
dataclass
¶
One event in the time-warp simulation.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
132 133 134 135 136 137 138 139 140 141 142 143 144 | |
Checkpoint
dataclass
¶
Deterministic state snapshot for rollback.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
CheckpointManager
¶
Manages state snapshots for time-warp rollback.
Preserves the identity substrate (ArcaneNeuron.v_deep) across rollback: deep compartment is NEVER rolled back.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
find_rollback_target(node_id, target_time_ns)
¶
Find the latest checkpoint at or before target_time.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
223 224 225 226 227 228 229 230 | |
discard_after(node_id, time_ns)
¶
Discard checkpoints after a given time (post-rollback cleanup).
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
232 233 234 235 236 237 | |
NodeState
dataclass
¶
Per-node state in the time-warp simulation.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
247 248 249 250 251 252 253 254 255 256 257 | |
TimeWarpEngine
¶
Optimistic parallel simulation with anti-message rollback.
Implements the Jefferson Time Warp protocol adapted for SC neuromorphic simulation:
- Each node advances optimistically at its own rate
- Straggler events trigger rollback + anti-messages
- Global Virtual Time (GVT) advances monotonically
- Fossil collection prunes checkpoints below GVT
- Identity (v_deep) is NEVER rolled back — it is the self
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
inject_event(event)
¶
Inject an event into the simulation.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
288 289 290 | |
process_next()
¶
Process the next event from the queue.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
compute_gvt()
¶
Compute Global Virtual Time (minimum of all LVTs + in-transit).
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
368 369 370 371 372 373 374 | |
fossil_collect()
¶
Remove checkpoints below GVT.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
376 377 378 379 380 381 382 383 384 385 | |
inject_sync_barrier(virtual_time_ns)
¶
Inject a sync barrier event to all nodes at given time.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
398 399 400 401 402 403 404 405 406 407 408 | |
verify_causal_order()
¶
Verify causal ordering of processed events.
Returns list of (index_a, index_b) pairs where order is violated.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
410 411 412 413 414 415 416 417 418 419 420 421 | |
detect_starvation(threshold_ns=10000)
¶
Detect nodes lagging behind GVT by more than threshold.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
423 424 425 426 427 428 | |
node_throughput()
¶
Events processed per node.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
430 431 432 | |
DivergenceMetric
dataclass
¶
Measures divergence between physical and digital twin.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
TwinSession
¶
Orchestrates physical ↔ digital twin synchronization.
Manages bidirectional data flow: - Physical → Digital: sensor events (MEA spikes, EEG) - Digital → Physical: stimulation commands (opto, TMS)
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
inject_physical_event(spike_time_ns, neuron_id, target_node=0)
¶
Inject a physical sensor event into the digital twin.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
advance(steps=1)
¶
Advance the simulation by N steps.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
512 513 514 515 516 517 518 519 520 521 | |
update_divergence(physical_rate_hz, digital_rate_hz, physical_identity)
¶
Update divergence metrics.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
LookaheadConfig
dataclass
¶
Null-message lookahead for conservative synchronization.
Each node declares a minimum time advance (lookahead) it guarantees before generating output events. Peers can safely advance by at least this amount without rollback risk.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 | |
NullMessageOptimizer
¶
Reduces rollbacks in mixed conservative/optimistic mode.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
safe_advance_time(node_id)
¶
Maximum time this node can safely advance to.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
586 587 588 589 590 591 | |
DeltaCheckpoint
dataclass
¶
Stores only the diff from a base checkpoint.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
ReplayVerifier
¶
Verifies bitstream-exact replay across runs.
Compares checkpoint hashes from two runs to prove determinism.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
DriftCorrection
dataclass
¶
One drift correction action.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
688 689 690 691 692 693 694 695 | |
DriftAutoCorrector
¶
Closed-loop drift correction between physical and digital twin.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
MPIRankMapping
dataclass
¶
Maps MPI ranks to physical node topology.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
728 729 730 731 732 733 734 735 736 737 738 739 740 | |
MPITopology
¶
Physical→logical node layout for distributed twin.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
co_located_ranks(rank)
¶
Ranks on the same host (cheap communication).
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
766 767 768 769 770 771 | |
BackpressureController
¶
Prevents event overload by throttling injection rate.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
CheckpointAuditChain
¶
Tamper-evident chain of checkpoint hashes.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
SessionSnapshot
dataclass
¶
Serializable session state for persistence.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
TwinEndpoint
dataclass
¶
One twin in a federation.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
888 889 890 891 892 893 894 | |
TwinFederation
¶
Federates multiple digital twins for multi-subject studies.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
AdaptiveCheckpointInterval
¶
Dynamically adjusts checkpoint frequency based on rollback rate.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
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 | |
update(total_rollbacks, total_events)
¶
Adjust interval: more rollbacks → more frequent checkpoints.
Source code in src/sc_neurocore/digital_twin/twinsync.py
| Python | |
|---|---|
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |