Skip to content

Commit

Permalink
added qiskit api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
claretgrace0801 committed Sep 5, 2022
1 parent f52457b commit 6da4f66
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 16 deletions.
1 change: 1 addition & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ numpydoc==1.4.0
matplotlib==3.5.2
docutils==0.17.1
sphinxcontrib-bibtex==2.4.2
qiskit==0.37.2
13 changes: 13 additions & 0 deletions doc/source/apidoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ Simulation based on the master equation.
qutip_qip.compiler
qutip_qip.pulse
qutip_qip.noise

Qiskit Circuit Simulation
--------------------------
Simulation of qiskit circuits based on qutip_qip backends.

.. autosummary::
:toctree: apidoc/
:template: autosummary/module.rst

qutip_qip.qiskit.backend
qutip_qip.qiskit.converter
qutip_qip.qiskit.provider
qutip_qip.qiskit.job
56 changes: 56 additions & 0 deletions doc/source/apidoc/qutip_qip.qiskit.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
:orphan:

qutip\_qip.qiskit.backend
===========================

.. automodule:: qutip_qip.qiskit.backend
:members:
:show-inheritance:

.. rubric:: Classes

.. autosummary::

QiskitSimulatorBase
QiskitCircuitSimulator
QiskitPulseSimulator

qutip\_qip.qiskit.converter
==============================

.. automodule:: qutip_qip.qiskit.converter
:members:
:show-inheritance:

.. rubric:: Methods

.. autosummary::

convert_qiskit_circuit

qutip\_qip.qiskit.provider
===========================

.. automodule:: qutip_qip.qiskit.provider
:members:
:show-inheritance:

.. rubric:: Classes

.. autosummary::

Provider

qutip\_qip.qiskit.job
===========================

.. automodule:: qutip_qip.qiskit.job
:members:
:show-inheritance:

.. rubric:: Classes

.. autosummary::

Job

24 changes: 17 additions & 7 deletions doc/source/qip-qiskit.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
******************************
Qiskit
******************************
.. _qip_qiskit:

**********************************
`qutip-qip` as a Qiskit backend
**********************************

This submodule was implemented by `Shreyas Pradhan <shpradhan12@gmail.com>`_ as part of Google Summer of Code 2022.

Overview
===============
Expand Down Expand Up @@ -42,8 +46,10 @@ Let's run this on the :class:`.QiskitCircuitSimulator` backend:
job = backend.run(circ)
result = job.result()
>>> from qiskit.visualization import plot_histogram
>>> plot_histogram(result.get_counts())
.. code-block::
from qiskit.visualization import plot_histogram
>>> plot_histogram(result.get_counts())
.. image:: /figures/qiskit-gate-level-plot.png
:alt: probabilities plot
Expand All @@ -58,7 +64,7 @@ While using a pulse processor, we define the circuit without measurements:
pulse_circ.h(0)
pulse_circ.h(1)
To use the :class:`.QiskitPulseSimulator` backend, we need to define the processor on which we want to run the circuit:
To use the :class:`.QiskitPulseSimulator` backend, we need to define the processor on which we want to run the circuit. This includes defining the pulse processor model with all the required parameters including noise.

.. code-block::
Expand All @@ -75,7 +81,9 @@ Now that we defined our processor (:class:`.LinearSpinChain` in this case), we c
pulse_job = pulse_backend.run(pulse_circ)
pulse_result = pulse_job.result()
>>> plot_histogram(pulse_result.get_counts())
.. code-block::
>>> plot_histogram(pulse_result.get_counts())
.. image:: /figures/qiskit-pulse-level-plot.png
:alt: probabilities plot
Expand All @@ -95,6 +103,8 @@ Qiskit's interface allows us to provide some options like ``shots`` while runnin
(Only available for :class:`.QiskitCircuitSimulator`)
``allow_custom_gate``, when set to ``False``, does not allowing simulating circuits that have user-defined gates; it will throw an error in that case. By default, it is set to ``True``, in which case, the backend will simulate a user-defined gate by computing its unitary matrix.

.. note::

The pulse backend does not allow simulation with user-defined gates.

An example demonstrating configuring options:
Expand Down
10 changes: 5 additions & 5 deletions src/qutip_qip/device/cavityqed.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ def sx_ops(self):
"""
list: A list of sigmax Hamiltonians for each qubit.
"""
return self.ctrls[0: self.num_qubits]
return self.ctrls[0 : self.num_qubits]

@property
def sz_ops(self):
"""
list: A list of sigmaz Hamiltonians for each qubit.
"""
return self.ctrls[self.num_qubits: 2 * self.num_qubits]
return self.ctrls[self.num_qubits : 2 * self.num_qubits]

@property
def cavityqubit_ops(self):
"""
list: A list of interacting Hamiltonians between cavity and each qubit.
"""
return self.ctrls[2 * self.num_qubits: 3 * self.num_qubits]
return self.ctrls[2 * self.num_qubits : 3 * self.num_qubits]

@property
def sx_u(self):
Expand All @@ -127,15 +127,15 @@ def sx_u(self):
@property
def sz_u(self):
"""array-like: Pulse matrix for sigmaz Hamiltonians."""
return self.coeffs[self.num_qubits: 2 * self.num_qubits]
return self.coeffs[self.num_qubits : 2 * self.num_qubits]

@property
def g_u(self):
"""
array-like: Pulse matrix for interacting Hamiltonians
between cavity and each qubit.
"""
return self.coeffs[2 * self.num_qubits: 3 * self.num_qubits]
return self.coeffs[2 * self.num_qubits : 3 * self.num_qubits]

def eliminate_auxillary_modes(self, U):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/qutip_qip/device/modelprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def pulse_matrix(self, dt=0.01):
t_idx_len = int(np.floor(dt_list[n] / dt))
mm = 0
for m in range(len(ctrls)):
u[mm, t_start: (t_start + t_idx_len)] = (
u[mm, t_start : (t_start + t_idx_len)] = (
np.ones(t_idx_len) * coeffs[n, m]
)
mm += 1
Expand Down
2 changes: 2 additions & 0 deletions src/qutip_qip/qiskit/backend.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Backends for simulating qiskit circuits."""

import numpy as np
import uuid
import random
Expand Down
4 changes: 3 additions & 1 deletion src/qutip_qip/qiskit/converter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Conversion of circuits from qiskit to qutip_qip."""

from qutip_qip.circuit import QubitCircuit
from qiskit.quantum_info import Operator
import numpy as np
Expand Down Expand Up @@ -94,7 +96,7 @@ def convert_qiskit_circuit(
qiskit_circuit : QuantumCircuit
QuantumCircuit to be converted to QubitCircuit.
all_custom_gate : bool
allow_custom_gate : bool
If False, this function will raise an error if
gate conversion is done using a custom gate's
unitary matrix.
Expand Down
6 changes: 4 additions & 2 deletions src/qutip_qip/qiskit/job.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Class for a running job."""

from qiskit.providers import JobV1, JobStatus
from qiskit.result import Result

Expand All @@ -8,14 +10,14 @@ class Job(JobV1):
Parameters
----------
backend : QiskitCircuitSimulator
backend : :class:`.QiskitCircuitSimulator`
The backend used to simulate a
circuit in the job.
job_id : str
Unique ID identifying a job.
result : qiskit.result.Result
result : :class:`qiskit.result.Result`
The result of a simulation run.
"""

Expand Down
2 changes: 2 additions & 0 deletions src/qutip_qip/qiskit/provider.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Provider for the simulator backends."""

from qiskit.providers.provider import ProviderV1
from .backend import QiskitCircuitSimulator, QiskitPulseSimulator

Expand Down

0 comments on commit 6da4f66

Please sign in to comment.