Skip to content

Commit

Permalink
Merge pull request #129 from iqm-finland/128-make-docs-reflect-iqm-re…
Browse files Browse the repository at this point in the history
…sonance

Add Example for IQM Resonance
  • Loading branch information
manzanillo authored Nov 14, 2024
2 parents 2544170 + efc582e commit 8303fa1
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

Version 15.4
============

* Update user guide to incorporate IQM Resonance. `#129 <https://github.com/iqm-finland/qiskit-on-iqm/pull/129>`_


Version 15.3
============

Expand Down
52 changes: 41 additions & 11 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,53 @@ code snippets and check the output yourself.

.. note::

At the moment IQM does not provide a quantum computing service open to the general public.
Please contact our `sales team <https://www.meetiqm.com/contact-us/>`_ to set up your access to an IQM quantum
computer.
IQM provides access to its quantum computers via IQM Resonance – IQM's quantum cloud service.
Please head over `to our website <https://www.meetiqm.com/products/iqm-resonance/>`_ to learn more.


Hello, world!
-------------

Here's the quickest and easiest way to run a small computation on an IQM quantum computer and check that
things are set up correctly:
Here's a quick and easy way to run a small computation on an IQM quantum computer to check that
things are set up correctly, either
through the IQM cloud service Resonance, or using an on-premises quantum computer.

IQM Resonance
~~~~~~~~~~~~~

1. Login to `IQM Resonance <https://resonance.meetiqm.com>` with your credentials.
2. Upon your first visit to IQM Resonance, you can generate your unique, non-recoverable API token
directly from the Dashboard page by selecting ``Generate token``. It's important to copy the token
immediately from the window, as you won't be able to do so once the window is closed. If you lose
your token, you have the option to regenerate it at any time. However, be aware that regenerating
your API token will invalidate any previously generated token.
3. Download one of the demo notebooks from `IQM Academy <https://www.iqmacademy.com/tutorials/>` or the
`resonance_example.py example file <https://raw.githubusercontent.com/iqm-finland/qiskit-on-iqm/main/src/iqm/qiskit_iqm/examples/resonance_example.py>`_
(Save Page As...)
4. Install Qiskit on IQM as instructed below.
5. Add your API token to the example (either as the parameter ``token`` to the :class:`.IQMProvider`
constructor, or by setting the environment variable :envvar:`IQM_TOKEN`)
5. Run the Jupyter notebook (or run ``python resonance_example.py`` if you decided to go for the Python script).
6. If you're connecting to a real quantum computer, the output should show almost half of the
measurements resulting in '00000' and almost half in '11111' – if this is the case, things are
set up correctly!

You can find a video guide on how to set things up `here <https://www.iqmacademy.com/tutorials/resonance/>`.
More ready-to-run examples can also be found at `IQM Academy <https://www.iqmacademy.com/tutorials/>`.


On-premises device
~~~~~~~~~~~~~~~~~~

1. Download the `bell_measure.py example file <https://raw.githubusercontent.com/iqm-finland/qiskit-on-iqm/main/src/iqm/qiskit_iqm/examples/bell_measure.py>`_ (Save Page As...)
2. Install Qiskit on IQM as instructed below (feel free to skip the import statement)
3. Install Cortex CLI and log in as instructed in the `documentation <https://iqm-finland.github.io/cortex-cli/readme.html#installing-cortex-cli>`__
4. Set the environment variable as instructed by Cortex CLI after logging in
5. Run ``$ python bell_measure.py --cortex_server_url https://demo.qc.iqm.fi/cocos`` – replace the example URL with the correct one
6. If you're connecting to a real quantum computer, the output should show almost half of the measurements resulting in '00' and almost half in '11' – if this is the case, things are set up correctly!
1. Download the `bell_measure.py example file <https://raw.githubusercontent.com/iqm-finland/qiskit-on-iqm/main/src/iqm/qiskit_iqm/examples/bell_measure.py>`_ (Save Page As...).
2. Install Qiskit on IQM as instructed below.
3. Install Cortex CLI and log in as instructed in the
`documentation <https://iqm-finland.github.io/cortex-cli/readme.html#installing-cortex-cli>`__
4. Set the environment variable as instructed by Cortex CLI after logging in.
5. Run ``$ python bell_measure.py --cortex_server_url https://demo.qc.iqm.fi/cocos`` – replace the example URL with the correct one.
6. If you're connecting to a real quantum computer, the output should show almost half of the
measurements resulting in '00' and almost half in '11' – if this is the case, things are set up
correctly!


Installation
Expand Down
47 changes: 47 additions & 0 deletions src/iqm/qiskit_iqm/examples/resonance_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2024 Qiskit on IQM developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This file is an example of using Qiskit on IQM to run a simple but non-trivial quantum circuit on
Resonance, the IQM quantum cloud service.
See the Qiskit on IQM user guide for instructions:
https://iqm-finland.github.io/qiskit-on-iqm/user_guide.html
"""

from iqm.qiskit_iqm import IQMProvider, transpile_to_IQM
from qiskit import QuantumCircuit

server_url = "https://cocos.resonance.meetiqm.com/<QUANTUM COMPUTER>" # For example https://cocos.resonance.meetiqm.com/garnet
api_token = "<INSERT YOUR TOKEN>"

SHOTS = 1000

# Define a quantum circuit
num_qb = 5
qc = QuantumCircuit(num_qb)

qc.h(0)
for qb in range(1, num_qb):
qc.cx(0, qb)
qc.barrier()
qc.measure_all()

# Initialize a backend
backend = IQMProvider(server_url, token=api_token).get_backend()

# Transpile the circuit
qc_transpiled = transpile_to_IQM(qc, backend)
print(qc_transpiled.draw(output="text"))

# Run the circuit
job = backend.run(qc_transpiled, shots=SHOTS)
print(job.result().get_counts())

0 comments on commit 8303fa1

Please sign in to comment.