Skip to content

Cudaq Frontend#2839

Open
ACE07-Sev wants to merge 6 commits intounitaryfoundation:mainfrom
ACE07-Sev:cudaquantum-frontend
Open

Cudaq Frontend#2839
ACE07-Sev wants to merge 6 commits intounitaryfoundation:mainfrom
ACE07-Sev:cudaquantum-frontend

Conversation

@ACE07-Sev
Copy link
Contributor

Description

Added initial commit for tackling #2200 .

License

  • I license this contribution under the terms of the GNU GPL, version 3 and grant Unitary Foundation the right to provide additional permissions as described in section 7 of the GNU GPL, version 3.

Before opening the PR, please ensure you have completed the following where appropriate.

@ACE07-Sev
Copy link
Contributor Author

@natestemen Greetings,

Hope you're doing well. Kindly have a look to see if it's good to go on the conversions.py side. Do lmk if you want additional or modified behavior.

Quick question, I couldn't add tests since I wasn't sure how you exactly determine what unit tests to be added for each frontend. I frankly couldn't really see a pattern/template based on the other frontends to add for cudaq, so please let me know what you'd like me to add testers for.

Copy link
Member

@natestemen natestemen left a comment

Choose a reason for hiding this comment

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

Thanks for getting this started! The first thing to do would be to add CUDAQ to the supported frontends:

class SUPPORTED_PROGRAM_TYPES(EnhancedEnum):

Once it's in there, it will be automatically tested via lots of the other tests. A few small, individual tests would also be good to see though. Just small circuit conversions.

Comment on lines 46 to 47
# We need to transpile as `openqasm3_to_cudaq` cannot work
# with arbitrary gates, i.e., ccx, rxx, etc.
Copy link
Member

Choose a reason for hiding this comment

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

It specifically only works with u3 and cx?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you mean qbraid's conversion, no, only single qubit gates and single controlled single qubit gates. Issue is that cudaq doesn't have ccx or mcx. They just do cx([0, 1, 2], [3]) for instance for mcx(replace indices there with qr[i] of course for correct syntax).

So, I thought it'd be better to just use u3 and cx when converting to cudaq side. It keeps maintenance easier, and would work for all custom gates.

@ACE07-Sev
Copy link
Contributor Author

Thanks for getting this started! The first thing to do would be to add CUDAQ to the supported frontends:

Copy that.

Once it's in there, it will be automatically tested via lots of the other tests. A few small, individual tests would also be good to see though. Just small circuit conversions.

Sure thing, I'll see if the tests pass for it.

@ACE07-Sev
Copy link
Contributor Author

Do I need to add the cudaq install to anywhere else besides pyproject.toml?

@ACE07-Sev
Copy link
Contributor Author

Sorry by the way for pushing this without making sure all tests pass. I'm having some trouble getting the test CI to run fully (keeps getting stuck at the end). I'm gonna test module by module for now.

@natestemen
Copy link
Member

Not a problem for continuing to test things out using GitHub actions here!

Since cudaq doesn't distribute wheels for non-linux OS's (NVIDIA/cuda-quantum#2065 (comment)), it might be worth considering how to run the tests only on linux builds. This is certainly possible, but we'll want to consider the tradeoff of complexity if we have to add lots of hacks to make it work. Typically for an isolated feature I might just say throw the tests in a new file and run those on the linux builds, but since this feature modifies QPROGRAM and many tests inspect that object to determine which tests to run, I don't see a clear path there. Maybe you have an idea?

@ACE07-Sev
Copy link
Contributor Author

it might be worth considering how to run the tests only on linux builds.

Sure, I'll update the workflow minimally to enable this with cudaq.

@ACE07-Sev
Copy link
Contributor Author

ACE07-Sev commented Oct 26, 2025

My ongoing notes on remaining tests that are failing. I fixed most, but these remain at the moment.

# These *seem* to be failing due to the floating point error introduced by cudaq which affects `has_stabilizer_effect` of cirq
FAILED mitiq/cdr/tests/test_cdr.py::test_execute_with_cdr[2-kwargs1-linear_fit_function-cudaq] - assert 0.0363123477534954 <= 0.005075633525848389
FAILED mitiq/cdr/tests/test_cdr.py::test_decorator_execute_with_cdr[2-kwargs1-linear_fit_function-cudaq] - assert 0.0363123477534954 <= 0.005075633525848389
FAILED mitiq/cdr/tests/test_cdr.py::test_mitigated_execute_with_cdr[2-kwargs1-linear_fit_function-cudaq] - assert 0.0363123477534954 <= 0.005075633525848389
FAILED mitiq/cdr/tests/test_clifford_utils.py::test_count_non_cliffords[cudaq] - assert 4 == 2

FAILED mitiq/cdr/tests/test_clifford_training_data.py::test_generate_training_circuits_any_qprogram[cudaq] - assert False

FAILED mitiq/pec/tests/test_pec.py::test_execute_with_pec_mitigates_noise[cudaq-serial_executor-circuit0] - assert 0.026311278343200684 < 0.026311278343200684
FAILED mitiq/pec/tests/test_pec.py::test_execute_with_pec_mitigates_noise[cudaq-serial_executor-circuit1] - assert 0.12331032752990723 < 0.12331032752990723
FAILED mitiq/pec/tests/test_pec.py::test_execute_with_pec_mitigates_noise[cudaq-batched_executor-circuit0] - assert 0.026311278343200684 < 0.026311278343200684
FAILED mitiq/pec/tests/test_pec.py::test_execute_with_pec_mitigates_noise[cudaq-batched_executor-circuit1] - assert 0.12331032752990723 < 0.12331032752990723

@ACE07-Sev ACE07-Sev mentioned this pull request Oct 26, 2025
6 tasks
@ACE07-Sev
Copy link
Contributor Author

It's not installing cudaq again hehe. I'll try to fix it.

@ACE07-Sev
Copy link
Contributor Author

I'll circle back to this soon.

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