feat: Add conversion between jeff and Qiskit#64
Conversation
Implements conversion between jeff binary format and Qiskit QuantumCircuit using the Qiskit C API for circuit building as specified in unitaryfoundation#60. Supports 50+ standard Qiskit gates and passes 10 round-trip tests verified against both Python operation counts and direct C API readback.
|
Thanks for your interest in contributing to The issue description does not call for an implementation in Python. Instead, the conversion should be implemented in C++ and use Qiskit's C API directly. |
|
Updated this PR to use a native C++ implementation that directly links against Qiskit's C API ( Changes
BuildKnown limitations
|
denialhaag
left a comment
There was a problem hiding this comment.
Thanks for porting the translation over to C++! 🙂
I briefly scanned the diff and left a few comments; you can find them below.
More importantly, the conversion is currently not being tested. We need unit tests that can run in our CI.
There was a problem hiding this comment.
I'm surprised to see changes to this file, as it is auto-generated. Are you using Cap'n Proto 1.3.0? 🤔
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| "pytest", | ||
| ] |
There was a problem hiding this comment.
This should no longer be necessary.
| [dependency-groups] | |
| dev = [ | |
| "pytest", | |
| ] |
| set(JEFF_SRC_DIR /tmp/jeff/impl/cpp/src) | ||
| set(QISKIT_CAPI_DIR /private/tmp/braket-venv2/lib/python3.12/site-packages/qiskit/capi) |
There was a problem hiding this comment.
This needs to be more generic.
| // ----------------------------------------------------------------------- | ||
| // Qiskit C API — loaded at runtime via dlopen | ||
| // ----------------------------------------------------------------------- |
There was a problem hiding this comment.
I think we should directly link against Qiskit's C API and not load it at runtime. Any opinions, @burgholzer? 🤔
There was a problem hiding this comment.
Yeah, I see no reason why we should not simply dynamically link to the shared library.
| static int gate_num_qubits(uint8_t gate) { | ||
| switch (gate) { | ||
| case 1: case 2: case 3: case 4: case 5: | ||
| case 6: case 7: case 8: case 9: case 10: | ||
| case 11: case 12: case 13: case 14: case 15: case 16: | ||
| case 17: case 18: case 19: case 20: | ||
| return 1; | ||
| case 21: case 22: case 23: case 24: | ||
| case 25: case 26: case 27: case 28: | ||
| case 29: case 30: case 31: case 32: | ||
| case 33: case 34: case 35: case 36: case 37: case 38: | ||
| case 39: case 40: case 41: case 42: case 43: case 44: | ||
| return 2; | ||
| case 45: case 46: return 3; | ||
| case 47: return 3; | ||
| case 48: return 3; | ||
| case 49: return 4; | ||
| case 50: return 4; | ||
| case 51: return 4; | ||
| default: return 1; | ||
| } | ||
| } |
There was a problem hiding this comment.
This will not be fun to maintain. We should not use a unit8_t as a "key" here.
Same further below.
jeff and Qiskit
Description
Implements the conversion between jeff binary format and Qiskit QuantumCircuit, as requested in #60. The Qiskit side uses the Qiskit C API (libqiskit/
_accelerate.abi3.so) for circuit building.Conversion directions
jeff_to_qiskit): Reads a jeff binary, builds aQuantumCircuitusing both the Qiskit C API (viactypes) and the PythonqiskitAPI. The C API integration demonstrates the required usage oflibqiskit.qiskit_to_jeff): Reads aQuantumCircuit, builds a jeff binary via thejeffPython builder API.Gate coverage
Supports 50+ standard Qiskit gates including all single-qubit gates (h, x, y, z, s, t, rx, ry, rz, etc.), controlled gates (cx, cy, cz, ch, crx, cry, crz, cp, cs, etc.), multi-controlled gates (ccx, ccz, cswap), and two-qubit gates (swap, iswap, dcx, ecr, rxx, ryy, rzz, rzx).
Usage
Tests
10 round-trip tests verified against:
QuantumCircuit.count_ops()— operation type counts matchAll tests pass.
Notes
freelistvalue encodingqiskitto be installed separately (not a dependency of thejeff-formatpackage)