Skip to content

Commit

Permalink
Azure Quantum plugin implementation (#573)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Claudino <[email protected]>
  • Loading branch information
danclaudino committed Aug 1, 2023
1 parent 29766e7 commit d1edaa7
Show file tree
Hide file tree
Showing 6 changed files with 552 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/source/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,39 @@ By default, it selects initialization parameters that are commonly best for a wi
| zero_threshold | Norm threshold for clamping probability amplitudes to 0 | double | 1e-14/1e-30 float/double |
+-----------------------------+------------------------------------------------------------------------+-------------+--------------------------+

Azure
+++++
The `Azure <https://learn.microsoft.com/en-us/azure/quantum/overview-azure-quantum>`_ accelerator plugin provides an interface to the Microsoft Azure Quantum cloud platform.

Users need to provide their Azure Quantum credentials via the ``$HOME/.azure_config`` with the following content:

.. code:: bash
location: [location]
Resource ID: [Azure_resource_ID]
.. code:: cpp
auto azure = xacc::getAccelerator("azure", {{"backend", "quantinuum.sim.h1-2e"}, {"shots", 500}});
.. code:: python
azure = xacc.getAccelerator("azure", {"backend": "quantinuum.sim.h1-2e", "shots": 500})
+-----------------------------+------------------------------------------------------------------------+-------------+--------------------------+
| Initialization Parameter | Parameter Description | type | default |
+=============================+========================================================================+=============+==========================+
| backend | Name of target backend | str | Must be provided |
+-----------------------------+------------------------------------------------------------------------+-------------+--------------------------+
| shots | Number of shots/samples | int | 1024 |
+-----------------------------+------------------------------------------------------------------------+-------------+--------------------------+
| visitor | Data format/structure to map XACC instructions to | str | pyqir |
+-----------------------------+------------------------------------------------------------------------+-------------+--------------------------+
| error-budget | Error threshold for QEC. Only for the microsoft.estimator backend | double | 0.005 |
+-----------------------------+------------------------------------------------------------------------+-------------+--------------------------+
| get-cost | Get HQC (cost) esimate for jobs on Quantinuum backends. | bool | false |
+-----------------------------+------------------------------------------------------------------------+-------------+--------------------------+

Algorithms
----------
XACC exposes hybrid quantum-classical Algorithm implementations for the variational quantum eigensolver (VQE), data-driven
Expand Down
39 changes: 39 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#
# Contributors:
# Alexander J. McCaskey - initial API and implementation
# Daniel Claudino - Azure plugin
# *******************************************************************************/
add_subdirectory(compiler)
add_subdirectory(plugins)
Expand Down Expand Up @@ -62,4 +63,42 @@ file(GLOB PYDECORATORS benchmark/chemistry/*.py benchmark/qpt/*.py
plugins/mitiq/*.py
plugins/pyzx/*.py
plugins/optimizers/*.py)

if(XACC_AZURE_PLUGIN)

if(Python_FOUND)
# check if azure-quantum[qiskit] plugin is installed
execute_process(COMMAND ${Python_EXECUTABLE} -c "import azure.quantum.qiskit" RESULT_VARIABLE AZURE_QUANTUM_EXISTS)

if(AZURE_QUANTUM_EXISTS EQUAL "1")
message(STATUS "${BoldGreen}Installing Azure Quantum with the Qiskit plugin.${ColorReset}")
execute_process(COMMAND ${Python_EXECUTABLE} -m pip install azure-quantum[qiskit])
# for the time being we have to downgrade the qiskit install because they just removed
# a class that azure uses for the Quantinuum cost estimate
execute_process(COMMAND ${Python_EXECUTABLE} -m pip install qiskit==0.43.3)
endif()

# check if pyqir is installed
execute_process(COMMAND ${Python_EXECUTABLE} -c "import pyqir" RESULT_VARIABLE PYQIR_EXISTS)

if(PYQIR_EXISTS EQUAL "1")
message(STATUS "${BoldGreen}Installing PyQIR.${ColorReset}")
execute_process(COMMAND ${Python_EXECUTABLE} -m pip install pyqir)
endif()

# check if multipledispatch is installed
execute_process(COMMAND ${Python_EXECUTABLE} -c "import multipledispatch" RESULT_VARIABLE MULTIPLE_DISPATCH_EXISTS)

if(MULTIPLE_DISPATCH_EXISTS EQUAL "1")
message(STATUS "${BoldGreen}Installing Multiple Dispatch.${ColorReset}")
execute_process(COMMAND ${Python_EXECUTABLE} -m pip install multipledispatch)
endif()

else()
message(STATUS "${BoldYellow}Python interpreter or development headers not found. Cannot install Azure Quantum plugin.${ColorReset}")
endif()

file(GLOB PYDECORATORS plugins/azure/*.py)

endif()
install(FILES ${PYDECORATORS} DESTINATION ${CMAKE_INSTALL_PREFIX}/py-plugins)
29 changes: 29 additions & 0 deletions python/examples/azure_bell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import xacc

xacc.qasm('''.compiler xasm
.circuit ansatz
.qbit q
H(q[0]);
CX(q[0],q[1]);
Measure(q[0]);
Measure(q[1]);
''')
ansatz = xacc.getCompiled('ansatz')
buffer = xacc.qalloc(2)

# running the estimator with the pyqir visitor and printing the data
qpu = xacc.getAccelerator('azure', {"shots": 1024, "backend": "microsoft.estimator", "visitor": "pyqir"})
qpu.execute(buffer, ansatz)
print(buffer["estimate-data"])

# running the IonQ simulator
buffer.resetBuffer()
qpu = xacc.getAccelerator('azure', {"shots": 1024, "backend": "ionq.simulator", "visitor": "qiskit"})
qpu.execute(buffer, ansatz)
print(buffer)

# runnning the Quantinuum emulator to estimate credits
buffer.resetBuffer()
qpu = xacc.getAccelerator('azure', {"shots": 1024, "backend": "quantinuum.sim.h1-2e", "visitor": "qiskit", "get-cost": True})
qpu.execute(buffer, ansatz)
print(buffer)
Loading

0 comments on commit d1edaa7

Please sign in to comment.