-
-
Notifications
You must be signed in to change notification settings - Fork 198
Cudaq Frontend #2839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ACE07-Sev
wants to merge
6
commits into
unitaryfoundation:main
Choose a base branch
from
ACE07-Sev:cudaquantum-frontend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cudaq Frontend #2839
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
64e14d3
- Initial commit to tackle #2200 .
ACE07-Sev dc2ac07
- Fixed some typing and format issues.
ACE07-Sev 9340a61
- Further changes to resolve failed tests.
ACE07-Sev b6a4f06
- Additional commits to reduce the number of unit test fails.
ACE07-Sev 830d894
Merge branch 'main' into cudaquantum-frontend
ACE07-Sev 5666fc8
- Resolved remaining test fails.
ACE07-Sev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copyright (C) Unitary Foundation | ||
| # | ||
| # This source code is licensed under the GPL license (v3) found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| from mitiq.interface.mitiq_cudaq.conversions import ( | ||
| from_cudaq, | ||
| to_cudaq, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Copyright (C) Unitary Foundation | ||
| # | ||
| # This source code is licensed under the GPL license (v3) found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| """Functions to convert between Mitiq's internal circuit representation and | ||
| Cuda-Quantum's circuit representation. | ||
| """ | ||
|
|
||
| from cirq import Circuit | ||
| from cudaq import PyKernel | ||
| from qbraid.transpiler.conversions.cirq import cirq_to_qasm2 | ||
| from qbraid.transpiler.conversions.cudaq import cudaq_to_qasm2 | ||
| from qbraid.transpiler.conversions.openqasm3 import openqasm3_to_cudaq | ||
| from qbraid.transpiler.conversions.qasm2 import qasm2_to_cirq, qasm2_to_qiskit | ||
| from qbraid.transpiler.conversions.qasm3 import qasm3_to_openqasm3 | ||
| from qbraid.transpiler.conversions.qiskit import qiskit_to_qasm3 | ||
|
|
||
|
|
||
| def from_cudaq(kernel: PyKernel) -> Circuit: | ||
| """Convert a cudaq PyKernel to a cirq Circuit via OpenQASM 3. | ||
|
|
||
| Args: | ||
| kernel (PyKernel): The cudaq PyKernel to convert. | ||
|
|
||
| Returns: | ||
| Circuit: The converted cirq Circuit. | ||
| """ | ||
| qasm2_str = cudaq_to_qasm2(kernel) | ||
| return qasm2_to_cirq(qasm2_str) | ||
|
|
||
|
|
||
| def to_cudaq(circuit: Circuit) -> PyKernel: | ||
| """Convert a cirq Circuit to a cudaq PyKernel via OpenQASM 3. | ||
|
|
||
| Args: | ||
| circuit (Circuit): The cirq Circuit to convert. | ||
|
|
||
| Returns: | ||
| PyKernel: The converted cudaq PyKernel. | ||
| """ | ||
| from qiskit import transpile | ||
|
|
||
| qasm2_str = cirq_to_qasm2(circuit) | ||
| qiskit_qc = qasm2_to_qiskit(qasm2_str) | ||
| # We need to transpile as `openqasm3_to_cudaq` cannot work | ||
| # with arbitrary gates, i.e., ccx, rxx, etc. | ||
| qiskit_qc = transpile(qiskit_qc, basis_gates=["u3", "cx"]) | ||
| qasm3_str = qiskit_to_qasm3(qiskit_qc) | ||
| openqasm3_str = qasm3_to_openqasm3(qasm3_str) | ||
| cudaq_qc = openqasm3_to_cudaq(openqasm3_str) | ||
|
|
||
| return cudaq_qc | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
u3andcx?There was a problem hiding this comment.
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 thatcudaqdoesn't have ccx or mcx. They just docx([0, 1, 2], [3])for instance for mcx(replace indices there withqr[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.