How netqir/netqir-sdk works
Project type and purpose
• This is an open‑source SDK (library) named “NetQIR SDK,” specifically the Python implementation called PyNetQIR.
• Its purpose is to let developers write and assemble quantum programs (QIR/NetQIR) in Python, using a high‑level builder API that targets the Microsoft Quantum Intermediate Representation (QIR) extended with NetQIR communication primitives.
File structure
Top‑level:
• setup.py, LICENSE, README.md – packaging and documentation
• python/ – the PyNetQIR package root
Under python/pynetqir:
• core/ – the main builder and program runtime
– builders/ – ScopeBuilder implementations (MainScopeBuilder, FunctionScopeBuilder)
– operation/ – IR node definitions (assembly ops, quantum ops, conditional, function, netqir comm ops, scopes)
– program.py – the Program façade (start, run, end, global state)
– traslation/ – translator/executor framework (printer executor, others)
• datatypes/ – definitions of QIR and NetQIR data types (Qubit, Result, Communicator, Rank)
• examples/ – sample Python scripts demonstrating teleporation and qsend/qrecv
Architectural clues:
– Builder pattern for constructing scopes and operations
– Core IR layer separated from datatypes
– Translation layer pluggable via executors (e.g., printer)
Key insights from README
– Program object coordinates lifecycle (start/end/run)
– Builders add operations to “global scope” or function scopes
– Example flows: Teleportation, NetQIR send/receive with conditional branching
– Emphasis on quantum and classical control, plus communicator initialization/finalization
a. Main components
1. User Code (python/examples)
2. Program API (Program class)
3. Scope Builders (MainScopeBuilder, FunctionScopeBuilder)
4. Operation IR Layer (operation.* modules)
5. Datatypes Layer (datatypes.* modules)
6. Translation/Executor Layer (executor printer, other executors)
7. External QIR/NetQIR Runtime (native runtime or simulator invoked by executor)
b. Relationships & interactions
– User Code calls Program.start()/get_global_scope()
– Builders invoke program IR methods to append Operation nodes
– Operation IR forms a tree/graph under Program
– At Program.run(), the Translation layer traverses the IR, serializes to QIR/NetQIR or invokes a backend executor
– Datatypes flow through builders and operations to represent registers, qubits, communicators
– Executor passes code to External Runtime or prints text
c. Architectural patterns & principles
– Builder Pattern: ScopeBuilder constructs sequences of Operation nodes
– Composite Pattern: Operation hierarchy represents nested scopes, functions, basic blocks
– Strategy Pattern: Multiple executors/printers can process the same IR
– Separation of Concerns: core (IR) vs datatypes vs translation/execution
d. Key technologies & frameworks
– Python 3.x packaging (setup.py)
– QIR (LLVM IR-based) and NetQIR extensions for communication
– asyncio or external MPI-like runtime (implied by communicator)
Elements
• Blue for user‑facing APIs (Program, Builders)
• Green for internal IR and datatypes
• Orange for translation/execution
• Gray for external systems
• Rectangles for modules
• Clouds for external runtimes
Final recommendations
• Lifecycle sequence: start() → build scopes → build IR → run() → translate → execute → end()
• Patterns (Builder, Composite, Strategy) where they occur to guide future contributors