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
@rniczh rniczh requested review from a team, mehrdad2m and paul0403 December 2, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants