Skip to content
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

Fix the rendering issue, refine the content. #44

Merged
merged 22 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aae152a
Fix the rendering issue
Mar 3, 2024
f8058d5
fix: Switch API docs entry point name
alecandido Mar 3, 2024
bd4f71e
fix: Use default Python code blocks, instead of Bash highlight
alecandido Mar 3, 2024
4029f48
adding missing navbar entries and fixing external links
scarrazza Mar 4, 2024
0fb0800
adding more details to quickstart file
Mar 4, 2024
fb5b755
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2024
db315d5
Adding docstring to quimb.py and eval_qu.py
Mar 4, 2024
a8c93cc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2024
bcacd9d
Add docstring
Tankya2 Mar 4, 2024
823e16d
Merge branch 'doc-fix' of https://github.com/qiboteam/qibotn into doc…
Tankya2 Mar 4, 2024
d3a1f4f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2024
8c16470
Add docstrings
Tankya2 Mar 4, 2024
f295bfd
Merge branch 'doc-fix' of https://github.com/qiboteam/qibotn into doc…
Tankya2 Mar 4, 2024
cda817f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2024
ac9fa21
Update docstrings and refine
Tankya2 Mar 4, 2024
07f433f
Merge branch 'doc-fix' of https://github.com/qiboteam/qibotn into doc…
Tankya2 Mar 4, 2024
014a39c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2024
e6a3060
Update docstrings and further refinement
Tankya2 Mar 4, 2024
7c7d860
Merge branch 'doc-fix' of https://github.com/qiboteam/qibotn into doc…
Tankya2 Mar 4, 2024
631231f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2024
16aef2b
Minor fix to docstring in quimb.py
Mar 4, 2024
a9730aa
Remove none type from docstring
Tankya2 Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 41 additions & 17 deletions doc/source/getting-started/quickstart.rst
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
Quick start
===========

In this section, we provide an example of two qubit ciruit simulation using qibotn package in Qibo simulator. First, the backend is to be set with appropriate run card settings, followed by the circuit simulation using Qibo documentation.

Setting the backend
"""""""""""""""""""
QiboTN supports two backends cutensornet (using CuQuantum library) and Quimbbackend (using Quimb library) for tensor network based simulations. The backend can be set using the following command line.

For CuQuantum library,
QiboTN offers two backends: cutensornet (using cuQuantum library) and qutensornet (using Quimb library) for tensor network based simulations. At present, cutensornet backend works only for GPUs whereas qutensornet for CPUs. The backend can be set using the following command line.

To use cuQuantum library, cutensornet can be specified as follows::

.. testcode::
qibo.set_backend(backend="qibotn", platform="cutensornet", runcard=computation_settings)
..
qibo.set_backend(
backend="qibotn", platform="cutensornet", runcard=computation_settings
)

and for Quimb library
Similarly, to use Quimb library, qutensornet can be set as follows::

.. testcode::
qibo.set_backend(
backend="qibotn", platform="QuimbBackend", runcard=computation_settings
backend="qibotn", platform="qutensornet", runcard=computation_settings
)
..

Setting the runcard
"""""""""""""""""""
Basic structure of runcard is

.. testcode::
The basic structure of the runcard is as follows::

computation_settings = {
"MPI_enabled": False,
"MPS_enabled": False,
Expand All @@ -32,21 +33,44 @@ Basic structure of runcard is
"pauli_string_pattern": "IXZ",
},
}
..


**MPI_enabled:** Setting this option *True* results in parallel execution of circuit using MPI (Message Passing Interface). At present, only works for cutensornet platform.

**MPS_enabled:** This option is set *True* for Matrix Product State (MPS) based calculations where as general tensor network structure is used for *False* value.

**NCCL_enabled:** This is set *True* for cutensoret interface for further acceleration while using Nvidia Collective Communication Library (NCCL).

**expectation_enabled:** This option is set *True* while calculating expecation value of the circuit. Observable whose expectation value is to be calculated is passed as a string in the dict format as {"pauli_string_pattern": "observable"}. When the option is set *False*, the dense vector state of the circuit is calculated.


Basic example
"""""""""""""

.. testcode::
# Construct the circuit
The following is a basic example to execute a two qubit circuit and print the final state in dense vector form using quimb backend::

# Set the quimb backend
qibo.set_backend(
backend="qibotn", platform="qutensornet", runcard=computation_settings
)

# Set the runcard
computation_settings = {
"MPI_enabled": False,
"MPS_enabled": False,
"NCCL_enabled": False,
"expectation_enabled": False,
}

# Construct the circuit with two qubits
c = Circuit(2)
# Add some gates

# Apply Hadamard gates on first and second qubit
c.add(gates.H(0))
c.add(gates.H(1))

# Execute the circuit and obtain the final state
result = c()

# Print the final state
print(result.state())

..
11 changes: 7 additions & 4 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ The supported HPC configurations are:

Currently, the supported tensor network libraries are:

- [cuQuantum](https://github.com/NVIDIA/cuQuantum), an NVIDIA SDK of optimized libraries and tools for accelerating quantum computing workflows.
- [quimb](https://quimb.readthedocs.io/en/latest/), an easy but fast python library for ‘quantum information many-body’ calculations, focusing primarily on tensor networks.
- `cuQuantum <https://github.com/NVIDIA/cuQuantum>`_, an NVIDIA SDK of optimized libraries and tools for accelerating quantum computing workflows.
- `quimb <https://quimb.readthedocs.io/en/latest/>`_, an easy but fast python library for ‘quantum information many-body’ calculations, focusing primarily on tensor networks.

How to Use the Documentation
============================
Expand All @@ -50,10 +50,10 @@ Contents
getting-started/index

.. toctree::
:maxdepth: 2
:maxdepth: 1
:caption: Main documentation

api-reference/modules
api-reference/qibotn
Developer guides <https://qibo.science/qibo/stable/developer-guides/index.html>

.. toctree::
Expand All @@ -64,6 +64,9 @@ Contents
Qibolab docs <https://qibo.science/qibolab/stable/>
Qibocal docs <https://qibo.science/qibocal/stable/>
Qibosoq docs <https://qibo.science/qibosoq/stable/>
Qibochem docs <https://qibo.science/qibochem/stable/>
Qibotn docs <https://qibo.science/qibotn/stable/>
Qibo-cloud-backends docs <https://qibo.science/qibo-cloud-backends/stable/>

Indices and tables
==================
Expand Down
15 changes: 12 additions & 3 deletions src/qibotn/backends/cutensornet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

class CuTensorNet(NumpyBackend): # pragma: no cover
# CI does not test for GPU
"""Creates CuQuantum backend for QiboTN."""

def __init__(self, runcard):
super().__init__()
Expand Down Expand Up @@ -92,6 +93,14 @@ def set_precision(self, precision):
super().set_precision(precision)

def cuda_type(self, dtype="complex64"):
"""Get CUDA Type.

Parameters:
dtype (str, optional): Either single ("complex64") or double (complex128) precision. Defaults to "complex64".

Returns:
CUDA Type: tuple of cuquantum.cudaDataType and cuquantum.ComputeType
"""
if dtype in CUDA_TYPES:
return CUDA_TYPES[dtype]
else:
Expand All @@ -100,15 +109,15 @@ def cuda_type(self, dtype="complex64"):
def execute_circuit(
self, circuit, initial_state=None, nshots=None, return_array=False
): # pragma: no cover
"""Executes a quantum circuit.
"""Executes a quantum circuit using selected TN backend.

Args:
Parameters:
circuit (:class:`qibo.models.circuit.Circuit`): Circuit to execute.
initial_state (:class:`qibo.models.circuit.Circuit`): Circuit to prepare the initial state.
If ``None`` the default ``|00...0>`` state is used.

Returns:
xxx.
QuantumState or numpy.ndarray: If `return_array` is False, returns a QuantumState object representing the quantum state. If `return_array` is True, returns a numpy array representing the quantum state.
"""

import qibotn.eval as eval
Expand Down
2 changes: 1 addition & 1 deletion src/qibotn/backends/quimb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def execute_circuit(
If ``None`` the default ``|00...0>`` state is used.

Returns:
xxx.
QuantumState or numpy.ndarray: If `return_array` is False, returns a QuantumState object representing the quantum state. If `return_array` is True, returns a numpy array representing the quantum state.
"""

import qibotn.eval_qu as eval
Expand Down
52 changes: 49 additions & 3 deletions src/qibotn/circuit_convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def __init__(self, circuit, dtype="complex128"):
self.circuit = circuit

def state_vector_operands(self):
"""Create the operands for dense vector computation in the interleave
format.

Returns:
Operands for the contraction in the interleave format.
"""
input_bitstring = "0" * len(self.active_qubits)

input_operands = self._get_bitstring_tensors(input_bitstring)
Expand Down Expand Up @@ -79,11 +85,25 @@ def _parse_gates_to_mode_labels_operands(
return mode_labels, operands

def op_shape_from_qubits(self, nqubits):
"""Modify tensor to cuQuantum shape (qubit_states,input_output) *
qubits_involved."""
"""Modify tensor to cuQuantum shape.

Parameters:
nqubits (int): The number of qubits in quantum circuit.

Returns:
(qubit_states,input_output) * nqubits
"""
return (2, 2) * nqubits

def init_intermediate_circuit(self, circuit):
"""Initialize the intermediate circuit representation.

This method initializes the intermediate circuit representation by extracting gate matrices and qubit IDs
from the given quantum circuit.

Parameters:
circuit (object): The quantum circuit object.
"""
self.gate_tensors = []
gates_qubits = []

Expand All @@ -105,13 +125,30 @@ def init_intermediate_circuit(self, circuit):
self.active_qubits = np.unique(gates_qubits)

def init_basis_map(self, backend, dtype):
"""Initialize the basis map for the quantum circuit.

This method initializes a basis map for the quantum circuit, which maps binary
strings representing qubit states to their corresponding quantum state vectors.

Parameters:
backend (object): The backend object providing the array conversion method.
dtype (object): The data type for the quantum state vectors.
"""
asarray = backend.asarray
state_0 = asarray([1, 0], dtype=dtype)
state_1 = asarray([0, 1], dtype=dtype)

self.basis_map = {"0": state_0, "1": state_1}

def init_inverse_circuit(self, circuit):
"""Initialize the inverse circuit representation.

This method initializes the inverse circuit representation by extracting gate matrices and qubit IDs
from the given quantum circuit.

Parameters:
circuit (object): The quantum circuit object.
"""
self.gate_tensors_inverse = []
gates_qubits_inverse = []

Expand All @@ -135,7 +172,7 @@ def init_inverse_circuit(self, circuit):
def get_pauli_gates(self, pauli_map, dtype="complex128", backend=cp):
"""Populate the gates for all pauli operators.

Args:
Parameters:
pauli_map: A dictionary mapping qubits to pauli operators.
dtype: Data type for the tensor operands.
backend: The package the tensor operands belong to.
Expand All @@ -159,6 +196,15 @@ def get_pauli_gates(self, pauli_map, dtype="complex128", backend=cp):
return gates

def expectation_operands(self, pauli_string):
"""Create the operands for pauli string expectation computation in the
interleave format.

Parameters:
pauli_string: A string representating the list of pauli gates.

Returns:
Operands for the contraction in the interleave format.
"""
input_bitstring = "0" * self.circuit.nqubits

input_operands = self._get_bitstring_tensors(input_bitstring)
Expand Down
9 changes: 9 additions & 0 deletions src/qibotn/circuit_to_mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@


class QiboCircuitToMPS:
"""A helper class to convert Qibo circuit to MPS.

Parameters:
circ_qibo: The quantum circuit object.
gate_algo(dict): Dictionary for SVD and QR settings.
datatype (str): Either single ("complex64") or double (complex128) precision.
rand_seed(int): Seed for random number generator.
"""

def __init__(
self,
circ_qibo,
Expand Down
Loading
Loading