-
Notifications
You must be signed in to change notification settings - Fork 291
Support dynamic quantum architecture for IQM QPUs #3298
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
base: main
Are you sure you want to change the base?
Changes from all commits
647afa0
b473371
09162a9
63828da
9914c16
30e7ddd
56c5e17
3f0d099
1067441
403d4ed
a472db4
41a4ce7
2bbc8f0
cc3e9e0
c922993
5b6c2e8
e0559db
a59cfb3
cd84da0
fb5bf88
48495aa
6e7131f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,7 +500,7 @@ jobs: | |
# Only the following tests are currently supported on IQM | ||
case $filename in | ||
targettests/iqm/*) | ||
nvq++ -DSYNTAX_CHECK --target iqm --iqm-machine Crystal_5 $filename | ||
nvq++ -DSYNTAX_CHECK --target iqm $filename | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I gather the new setup is that different machines will be accessible via different server urls? |
||
test_status=$? | ||
if [ $test_status -eq 0 ]; then | ||
./a.out | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Compile and run with: | ||
// ``` | ||
// nvq++ --target iqm iqm.cpp --iqm-machine Crystal_5 -o out.x && ./out.x | ||
// nvq++ --target iqm iqm.cpp -o out.x && ./out.x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally, we try to make sure that changes are non-breaking (current API still works but gives a deprecated warning for some time before we remove it in favor of a different API). It would be good if we could have one test for python and one for C++ that checks the old API still works (possibly giving a warning or error if necessary with instructions for what should be used instead). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the architecture information is now fetched from the target machine (URL) giving it as parameter is no longer necessary and the parsing of the parameter was removed. From backward compatibility point nothing bad will happen if it is still given. It can however be confusing that this parameter is ignored and we can give a warning/information about this if desired. |
||
// ``` | ||
// Assumes a valid set of credentials have been stored. | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -113,34 +113,49 @@ IQM | |||||
|
||||||
.. _iqm-backend: | ||||||
|
||||||
Support for submissions to IQM is currently under development. | ||||||
In particular, two-qubit gates can only be performed on adjacent qubits. For more information, we refer to the respective hardware documentation. | ||||||
The `IQM Resonance <https://meetiqm.com/products/iqm-resonance/>`__ portal offers access to various different IQM quantum computers. | ||||||
The machines available will be constantly extended as development progresses. | ||||||
Programmers of CUDA-Q may access the IQM Server from either C++ or Python. | ||||||
|
||||||
With this version it is no longer necessary to define the target QPU architecture in the code or at compile-time. | ||||||
The IQM backend integration now contacts at runtime the configured IQM server and fetches the active dynamic quantum architecture of the QPU. | ||||||
This is then used as input to transpile the quantum kernel code just-in-time for the target QPU topology. | ||||||
By setting the environment variable ``IQM_SERVER_URL`` the target server can be selected just when executing the program. | ||||||
As result the python script or the compiled C++ program can be executed on different QPUs without any changes to the code. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
|
||||||
For IQM architectures two-qubit gates can only be performed on adjacent qubits. For more information, we refer to the respective hardware documentation. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These last two sentences here are outdated and should be removed. For application code, the execution on IQM backends should be supported regardless of what gates are used on which qubits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the confirmation. I was unsure about this since these lines were recently rewritten. So I left them as they were. I will update accordingly. |
||||||
Support for automatically injecting the necessary operations during compilation to execute arbitrary multi-qubit gates will be added in future versions. | ||||||
|
||||||
Setting Credentials | ||||||
````````````````````````` | ||||||
|
||||||
Programmers of CUDA-Q may access the IQM Server from either C++ or Python. Following the `quick start guide <https://iqm-finland.github.io/cortex-cli/readme.html#using-cortex-cli>`__, install `iqm-cortex-cli` and login to initialize the tokens file. | ||||||
The path to the tokens file can either be passed explicitly via an environment variable or it will be loaded automatically if located in | ||||||
the default location :code:`~/.cache/iqm-cortex-cli/tokens.json`. | ||||||
Create a free account on the `IQM Resonance <https://meetiqm.com/products/iqm-resonance/>`__ portal and log-in. | ||||||
Navigate to the account profile (top right). There generate an "API Token" and copy the generated token-string. | ||||||
Set the environment variable ``IQM_TOKEN`` to contain the value of the token-string. | ||||||
The IQM backend integration will use this as authorization token at the IQM server. | ||||||
|
||||||
Note: The previously used ``IQM_TOKENS_FILE`` environment variable can still be used to point to a tokens file but will be ignored if the ``IQM_TOKEN`` variable is set. | ||||||
The tokens file cannot be generated by the ``iqmclient`` tool anymore but needs to be created manually using the token obtained from the Resonance profile page. | ||||||
A token file can be created and the environment variable set like this: | ||||||
|
||||||
.. code:: bash | ||||||
|
||||||
export IQM_TOKENS_FILE="path/to/tokens.json" | ||||||
echo '{ "access_token": "<put-your-token-here>" }' > resonance-token.json | ||||||
export IQM_TOKENS_FILE="path/to/resonance-tokens.json" | ||||||
|
||||||
Please find more documentation after logging in to the IQM Resonance portal. | ||||||
|
||||||
|
||||||
Submitting | ||||||
````````````````````````` | ||||||
.. tab:: Python | ||||||
|
||||||
.. tab:: Python | ||||||
|
||||||
The target to which quantum kernels are submitted | ||||||
can be controlled with the ``cudaq.set_target()`` function. | ||||||
|
||||||
.. code:: python | ||||||
|
||||||
cudaq.set_target("iqm", url="https://<IQM Server>/cocos",**{"qpu-architecture": "Crystal_5"}) | ||||||
cudaq.set_target("iqm", url="https://<IQM Server>/") | ||||||
|
||||||
To emulate the IQM Server locally, without submitting to the IQM Server, | ||||||
you can also set the ``emulate`` flag to ``True``. This will emit any target | ||||||
|
@@ -157,39 +172,33 @@ Submitting | |||||
.. code:: python | ||||||
|
||||||
cudaq.sample(kernel, shots_count=10000) | ||||||
|
||||||
|
||||||
To see a complete example for using IQM server backends, take a look at our :doc:`Python examples<../../examples/examples>`. | ||||||
|
||||||
|
||||||
.. tab:: C++ | ||||||
|
||||||
To target quantum kernel code for execution on an IQM Server, | ||||||
pass the ``--target iqm`` flag to the ``nvq++`` compiler, along with a specified ``--iqm-machine``. | ||||||
|
||||||
.. note:: | ||||||
The ``--iqm-machine`` is a mandatory argument. This provided architecture must match | ||||||
the device architecture that the program has been compiled against. The hardware architecture for a | ||||||
specific IQM Server may be checked via `https://<IQM server>/cocos/quantum-architecture`. | ||||||
To target quantum kernel code for execution on an IQM Server, | ||||||
pass the ``--target iqm`` flag to the ``nvq++`` compiler. | ||||||
|
||||||
.. code:: bash | ||||||
|
||||||
nvq++ --target iqm --iqm-machine Crystal_5 src.cpp | ||||||
nvq++ --target iqm src.cpp | ||||||
|
||||||
Once the binary for a specific IQM QPU architecture is compiled, it can be executed against any IQM Server with the same QPU architecture: | ||||||
Once the binary for an IQM QPU is compiled, it can be executed against any IQM Server: | ||||||
|
||||||
.. code:: bash | ||||||
|
||||||
nvq++ --target iqm --iqm-machine Crystal_5 src.cpp -o program | ||||||
IQM_SERVER_URL="https://demo.qc.iqm.fi/cocos" ./program | ||||||
|
||||||
# Executing the same program against an IQM Server with a different underlying QPU | ||||||
# architecture will result in an error. | ||||||
IQM_SERVER_URL="https://<Crystal_20 IQM Server>/cocos" ./program | ||||||
nvq++ --target iqm src.cpp -o program | ||||||
IQM_SERVER_URL="https://demo.qc.iqm.fi/" ./program | ||||||
|
||||||
To emulate the IQM machine locally, without submitting to the IQM Server, | ||||||
you can also pass the ``--emulate`` flag to ``nvq++``. This will emit any target | ||||||
specific compiler diagnostics, before running a noise free emulation. | ||||||
|
||||||
.. code:: bash | ||||||
|
||||||
nvq++ --emulate --target iqm --iqm-machine Crystal_5 src.cpp | ||||||
nvq++ --emulate --target iqm src.cpp | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe emulation would not work fully as expected - it would not do include the layout for a specific device. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of emulation the code currently uses the static Crystal_20.txt file as architecture. This is more a workaround than a solution since there is no machine in this case. With this the emulation testcases pass while they stay below 20 qubits (basically). We still allow the user to pass a "mapping_file" but I would not expect that anybody would do this for the emulation mode. There is the "mapping" testcase which still uses and tests this parameter.
|
||||||
|
||||||
To see a complete example, take a look at :ref:`IQM examples <iqm-examples>`. | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,14 @@ | |
# ============================================================================ # | ||
target_sources(cudaq-rest-qpu PRIVATE IQMServerHelper.cpp) | ||
add_target_config(iqm) | ||
add_target_mapping_arch(iqm "Crystal_5.txt") | ||
add_target_mapping_arch(iqm "Crystal_20.txt") | ||
add_target_mapping_arch(iqm "Crystal_54.txt") | ||
add_target_mapping_arch(iqm Crystal_20.txt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also be removed here, and instead someone that uses emulation should create an appropriate file themselves (maybe we can have an option to dump the architecture file for a specific url instead of deleting it?). The section in the docs about emulation needs to clarify this, and could link to the files used for testing as an example. |
||
|
||
|
||
add_library(cudaq-serverhelper-iqm SHARED IQMServerHelper.cpp ) | ||
target_link_libraries(cudaq-serverhelper-iqm | ||
PUBLIC | ||
cudaq-common | ||
fmt::fmt-header-only | ||
PUBLIC | ||
cudaq-common | ||
fmt::fmt-header-only | ||
) | ||
install(TARGETS cudaq-serverhelper-iqm DESTINATION lib) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this setup, I think we should no longer have any architecture files checked in in the runtime. The Crystal_5 and Crystal_20 files used for testing can be added to the appropriate test directory instead. |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.