Skip to content

Conversation

@rniczh
Copy link
Contributor

@rniczh rniczh commented Nov 18, 2025

Context:

Convert ion dialect to rtio dialect

Description of the Change:

There are several steps to convert the ion dialect to rtio dialect:

  1. Prepare the enviorment:

    • Import device db json to rtio.config
    • Collect ION infos
    • Create a kernel function, which is just cloned from the original qnode function
    • Drop the pulse with transition 0, that's because that can't be applied on the current device, and it will be dropped in the current ARTIQ's compilation flow as well
    • Initialize memref map: Construct mapping from qreg alloc and qreg extract to memref. In the later conversion, we use the mapping to construct the channel for rtio.pulse. It will create a global memref that contains index from 0 to N to represent the qubits.
  2. parallel protocol to rtio:
    Converts ion.parallelprotocol regions into flat RTIO operations with proper synchronization. We rely on the data dependency of qubit to introduce the unrealized conversion cast between ion.qubit and rtio.event. That's the way how we currently build the relationship between events. Later, those unrealized conversion cast will be removed via event propagation.

    Input mlir:

     %0, %1 = ion.parallelprotocol(%q0, %q1) {
       ^bb0(%arg0, %arg1):
       %p0 = rtio.pulse(...) : !rtio.event
       %p1 = rtio.pulse(...) : !rtio.event
       ion.yield %arg0, %arg1
     }
     %event0 = unrealized_conversion_cast %q0 : !ion.qubit -> !rtio.event
     %event1 = unrealized_conversion_cast %q1 : !ion.qubit -> !rtio.event
     %p0 = rtio.pulse(..., wait = %inputSync) : !rtio.event
     %p1 = rtio.pulse(..., wait = %inputSync) : !rtio.event
     %sync = rtio.sync %p0, %p1 : !rtio.event
     %0 = unrealized_conversion_cast %sync : !rtio.event -> !ion.qubit
     %1 = unrealized_conversion_cast %sync : !rtio.event -> !ion.qubit
  3. ion.pulse to rtio.pulse:
    Converts ion.pulse to rtio.pulse with calculated frequency.

    Frequency Calculation:

    frequency = (reference_energy + detuning - raman1_frequency) / (2 * pi)

    Steps:

    • Extract pulse parameters (duration, beam, phase)
    • Calculate frequency from transition index and detuning
    • Create rtio.channel via rtio.qubit_to_channel
    • Generate rtio.pulse operation
  4. Resolve channel mapping
    Resolves dynamic channel references to static channel IDs.

    memref.global (constants) -> memref.get_global -> memref.load -> qubit_to_channel
    
    // Before
    %ch = rtio.qubit_to_channel %qubit : !ion.qubit -> !rtio.channel<"dds", ?>
    
    // After
    %ch = rtio.channel "dds" { channel_id = N } : !rtio.channel<"dds">
  5. propagate events
    Resolves unrealized_conversion_cast and connect the ops with event type

    Steps:

    • Trace backward to collect all the source events.
    • Create sync from collected events
    • If reaches quantum.AllocOp: create rtio.empty
  6. Remove all other dialects:
    Removes unused quantum/ion/memref/linalg dialect after conversion.

TODOs:

  • Add lit tests

Benefits:

Possible Drawbacks:

Related GitHub Issues:
[sc-100851]

@rniczh rniczh changed the title Rniczh/lower ion to rtio Lower ion to rtio Nov 18, 2025
@rniczh rniczh changed the base branch from main to rniczh/add-rtio-dialect November 18, 2025 05:53
@rniczh rniczh marked this pull request as draft November 18, 2025 05:57
@rniczh rniczh marked this pull request as ready for review November 25, 2025 06:41
Base automatically changed from rniczh/add-rtio-dialect to main December 4, 2025 01:34
@mehrdad2m mehrdad2m self-requested a review December 7, 2025 14:13
@rniczh rniczh added the OQD OQD-related work label Dec 8, 2025
Copy link
Contributor

@mehrdad2m mehrdad2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.21%. Comparing base (1001ed1) to head (dcc2ae5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2204      +/-   ##
==========================================
+ Coverage   97.19%   97.21%   +0.01%     
==========================================
  Files          93       93              
  Lines       11248    11243       -5     
  Branches     1078     1075       -3     
==========================================
- Hits        10933    10930       -3     
+ Misses        247      246       -1     
+ Partials       68       67       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OQD OQD-related work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants