Skip to content

Add conversions between Jeff and arith, math, and tensor#10

Merged
burgholzer merged 27 commits into
mainfrom
arith-and-tensor
Mar 18, 2026
Merged

Add conversions between Jeff and arith, math, and tensor#10
burgholzer merged 27 commits into
mainfrom
arith-and-tensor

Conversation

@denialhaag
Copy link
Copy Markdown
Collaborator

@denialhaag denialhaag commented Mar 10, 2026

This PR adds conversions between Jeff and the built-in arith, math, and tensor dialects. The conversions can round-trip all Int_Ops, IntArray_Ops, Float_Ops, and FloatArray_Ops.

@denialhaag denialhaag self-assigned this Mar 10, 2026
@denialhaag denialhaag added the enhancement New feature or request label Mar 10, 2026
Comment thread lib/Conversion/MathToJeff/MathToJeff.cpp Outdated
Copy link
Copy Markdown
Collaborator Author

@denialhaag denialhaag left a comment

Choose a reason for hiding this comment

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

Apart from the tests and the linter errors, this is practically ready.

Unfortunately, the testing is giving me quite a headache. I really wanted to reuse the .jeff files and implement round-trip tests. However, this is currently forcing quite some less-than-ideal workarounds to prevent constant folding. At this point, I feel like we might need to write string-based unit tests that test each conversion individually.

@burgholzer, do you see any alternative? 🤔

Comment thread unittests/Conversion/test_native_round_trip.cpp Outdated
Comment thread unittests/Conversion/test_native_round_trip.cpp Outdated
Comment thread lib/Conversion/ArithToJeff/ArithToJeff.cpp Outdated
Copy link
Copy Markdown
Collaborator

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

Thanks @denialhaag for working on this. Gave this a quick review and, as always, you will find some comments inline. I hope these make sense. Some might require a bit of discussion.

Comment thread unittests/Conversion/test_native_round_trip.cpp Outdated
Comment thread unittests/Conversion/test_native_round_trip.cpp Outdated
Comment thread unittests/Conversion/test_native_round_trip.cpp Outdated
Comment thread unittests/Conversion/test_native_round_trip.cpp
Comment thread unittests/Translation/CMakeLists.txt Outdated
Comment thread lib/Conversion/JeffToArith/JeffToArith.cpp Outdated
Comment thread lib/Conversion/JeffToArith/JeffToArith.cpp Outdated
Comment thread lib/Conversion/ArithToJeff/ArithToJeff.cpp Outdated
Comment thread lib/Conversion/JeffToMath/JeffToMath.cpp Outdated
Comment thread lib/Conversion/TensorToJeff/TensorToJeff.cpp Outdated
@denialhaag denialhaag force-pushed the arith-and-tensor branch 2 times, most recently from 46b94cd to d58e309 Compare March 13, 2026 13:53
Comment thread lib/Conversion/NativeToJeff/NativeToJeff.cpp
Comment thread lib/Translation/Deserialize.cpp
@denialhaag denialhaag marked this pull request as ready for review March 16, 2026 19:00
@denialhaag denialhaag requested a review from burgholzer March 16, 2026 19:00
Copy link
Copy Markdown
Collaborator

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

I just gave this another (very quick) round of review. All of the comments are minor. Once addressed, this is good to go from my side.
Maybe @dime10 wants to have a quick look as well?

Comment thread lib/IR/JeffOps.cpp Outdated
Comment thread lib/Translation/CMakeLists.txt
Comment thread lib/Translation/Deserialize.cpp
Comment thread lib/Conversion/NativeToJeff/NativeToJeff.cpp
Co-authored-by: Lukas Burgholzer <burgholzer@me.com>
@denialhaag denialhaag requested a review from dime10 March 16, 2026 22:57
@denialhaag
Copy link
Copy Markdown
Collaborator Author

After a discussion in munich-quantum-toolkit/core#1565 (comment), we have decided to make some more changes to the native-to-Jeff conversion:

  • Cast operations are now removed during the conversion. This should always be fine because the conversion creates Jeff operations with the correct type. The cast operations should thus only be artifacts that made the native program valid.

  • The native-to-Jeff conversion seems very clean to me now because the arith, math, and tensor dialects are marked illegal without exceptions. In general, the conversion logic is very straightforward now.

  • It became necessary to convert arith.constant operations of type index to jeff.int_const_32 operations. If I'm not completely mistaken, this is in the spirit of the Jeff specification because arrays are indexed using int(32): https://github.com/unitaryfoundation/jeff/blob/main/impl/capnp/jeff.capnp#L964-L972

  • Unfortunately, the change broke four round-trip tests because the IR is no longer identical (but still equivalent, of course):

    Input:

    func.func @main() {
      %0 = jeff.int_const32(2) : i32
      %1 = jeff.int_array_const32([1, 2, 3]) : tensor<?xi32>
      %2 = jeff.int_array_get_index(%0) %1 : i32, tensor<?xi32> -> i32
      return
    }
    

    Output:

    func.func @main() {
      %0 = jeff.int_array_const32([1, 2, 3]) : tensor<?xi32>
      %1 = jeff.int_const32(2) : i32
      %2 = jeff.int_array_get_index(%0) %1 : i32, tensor<?xi32> -> i32
      return
    }
    

    I'm leaning toward living with this and skipping these tests, but I'm open to being convinced.

If both @burgholzer and @dime10 agree, I'd say we can merge this later today.

@dime10
Copy link
Copy Markdown
Collaborator

dime10 commented Mar 18, 2026

Thank you for the updates @denialhaag! In terms of round-tripping, I would say as long as the jeff mlir dialect and the jeff format round-trip, that's the most important. From other dialects to the jeff dialect I would expect some (non-meaningful) loss because there are different abstractions involved.

Copy link
Copy Markdown
Collaborator

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

Excellent work 🙌

Comment thread include/jeff/Conversion/NativeToJeff/NativeToJeff.td Outdated
Comment thread include/jeff/Conversion/NativeToJeff/NativeToJeff.td Outdated
Comment thread include/jeff/Conversion/JeffToNative/JeffToNative.td Outdated
Copy link
Copy Markdown
Collaborator

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

Looks like this is ready to be merged. 🚀
Let's go.

@burgholzer burgholzer merged commit c7e0d03 into main Mar 18, 2026
6 checks passed
@burgholzer burgholzer deleted the arith-and-tensor branch March 18, 2026 19:41
denialhaag added a commit to munich-quantum-toolkit/core that referenced this pull request Mar 18, 2026
## Description

This PR updates `jeff-mlir` to the latest version, allowing us to use
the conversion passes added in
PennyLaneAI/jeff-mlir#10.

## Checklist

- [x] The pull request only contains commits that are focused and
relevant to this change.
- [x] ~~I have added appropriate tests that cover the new/changed
functionality.~~
- [x] ~~I have updated the documentation to reflect these changes.~~
- [x] I have added entries to the changelog for any noteworthy
additions, changes, fixes, or removals.
- [x] ~~I have added migration instructions to the upgrade guide (if
needed).~~
- [x] The changes follow the project's style guidelines and introduce no
new warnings.
- [x] The changes are fully tested and pass the CI checks.
- [x] I have reviewed my own code changes.

---------

Signed-off-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
Co-authored-by: Lukas Burgholzer <burgholzer@me.com>
denialhaag added a commit to munich-quantum-toolkit/core that referenced this pull request Mar 19, 2026
## Description

As pointed out in
PennyLaneAI/jeff-mlir#10 (comment),
a conversion only depends on a dialect if it _creates_ its operations.
This PR fixes the definition of all conversions accordingly.

## Checklist

- [x] The pull request only contains commits that are focused and
relevant to this change.
- [x] ~~I have added appropriate tests that cover the new/changed
functionality.~~
- [x] ~~I have updated the documentation to reflect these changes.~~
- [x] I have added entries to the changelog for any noteworthy
additions, changes, fixes, or removals.
- [x] ~~I have added migration instructions to the upgrade guide (if
needed).~~
- [x] The changes follow the project's style guidelines and introduce no
new warnings.
- [x] The changes are fully tested and pass the CI checks.
- [x] I have reviewed my own code changes.

---------

Signed-off-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants