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

implementing the Quantum Matcha Tea backend #86

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
773196f
refactor: constructing an abstract QiboTN backend and adapt quimb and…
MatteoRobbiati Jan 27, 2025
f1aec1f
feat: abstract qibotn backend
MatteoRobbiati Jan 27, 2025
a979d97
feat: drafting qmatchatea backend
MatteoRobbiati Jan 27, 2025
43ebd79
feat: add qmatchatea backend to __init__ backends file
MatteoRobbiati Jan 27, 2025
80bfc7e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 27, 2025
508d5cd
feat: integrating qmatchatea SimulationResult in the circuit execution
MatteoRobbiati Jan 27, 2025
429e15d
feat: integrating qmatchatea SimulationResult in the circuit execution
MatteoRobbiati Jan 27, 2025
85e2e39
feat: improving execute_circuit method by adding a TensorNetworkResul…
MatteoRobbiati Jan 28, 2025
1268888
feat: TensorNetworkResult object implementation
MatteoRobbiati Jan 28, 2025
6fe2c32
fix: removed unused default_runcard dictionary
MatteoRobbiati Jan 28, 2025
91b4b63
refactor: move the imports outside of the backend init
MatteoRobbiati Jan 28, 2025
ce40c7b
fix: TensorNetworkResult error raising
MatteoRobbiati Jan 28, 2025
66288ac
feat: add method to compute expectation values from symbolic form of …
MatteoRobbiati Jan 28, 2025
dc02764
doc: add example introduction to qmatchatea backend
MatteoRobbiati Jan 28, 2025
ad40a8b
chore: updating lock
MatteoRobbiati Jan 29, 2025
a609dfa
chore: rerun pre-commit
MatteoRobbiati Jan 29, 2025
97a1568
chore: updating pre-commit once more
MatteoRobbiati Jan 29, 2025
13789e5
chore: aligning pre-commit with Qibo's
MatteoRobbiati Jan 29, 2025
e510c8b
fix: conflicts in pre-commit config with main
MatteoRobbiati Jan 29, 2025
29ca504
test: add conftest and first observable test
MatteoRobbiati Jan 30, 2025
4cc1452
adapt pre-commit to qibo's one
MatteoRobbiati Jan 30, 2025
67b900b
fix: set config_backend as normal method and not abstract method (for…
MatteoRobbiati Feb 3, 2025
08ad49e
feat: make statevector calculation optional
MatteoRobbiati Feb 3, 2025
4a2362e
feat: add set_device method to TN abstract backend
MatteoRobbiati Feb 3, 2025
1036075
fix: probabilities results in case of prob_type=U
MatteoRobbiati Feb 3, 2025
d15a3d9
refactor: renaming expectation test
MatteoRobbiati Feb 3, 2025
f420a94
test: circuit execution
MatteoRobbiati Feb 3, 2025
f6992b4
Merge branch 'matcha' of github.com:qiboteam/qibotn into matcha
MatteoRobbiati Feb 3, 2025
8b7bb9e
doc: improving the docs
MatteoRobbiati Feb 4, 2025
65b60e0
fix: probabilities method in result class
MatteoRobbiati Feb 4, 2025
39ed3eb
doc: use qibo's GHZ state function
MatteoRobbiati Feb 10, 2025
72ba416
Apply suggestions from code review
MatteoRobbiati Feb 10, 2025
938bf13
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
d959c95
Merge branch 'matcha' of github.com:qiboteam/qibotn into matcha
MatteoRobbiati Feb 10, 2025
3e9189e
refactor: probabilities are now returned as an array, being aligned w…
MatteoRobbiati Feb 10, 2025
d854d15
fix: add link to api reference
MatteoRobbiati Feb 10, 2025
a5f7d1f
refactor: make QibotnBackend abstract and inherit both this and Numpy…
MatteoRobbiati Feb 10, 2025
30c3bba
fix: change the order or the inheritance to impose the correct __mro__
MatteoRobbiati Feb 10, 2025
97d2c79
doc: improve docstrings related to TensorNetworkResult
MatteoRobbiati Feb 10, 2025
309fdc9
fix: importing QmatchateaBackend inside proper condition in the __ini…
MatteoRobbiati Feb 10, 2025
4683c60
Update src/qibotn/result.py
MatteoRobbiati Feb 10, 2025
afc6c5d
Update src/qibotn/backends/qmatchatea.py
MatteoRobbiati Feb 10, 2025
bb76e2b
refactor: rewrite the expectation method using Qibo built in features
MatteoRobbiati Feb 10, 2025
5b63877
refactor: adapt the example to the new expectation function
MatteoRobbiati Feb 10, 2025
292d357
feat: improve the configure_tn_simulation function so that we don't n…
MatteoRobbiati Feb 10, 2025
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
21 changes: 1 addition & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ repos:
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place, --config, ./pyproject.toml]
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
Expand All @@ -32,17 +26,4 @@ repos:
rev: v2.5.0
hooks:
- id: pycln
args:
- --config=pyproject.toml
- --all
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.19.1
hooks:
- id: blacken-docs
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
args:
- --select=D103,D200,D206,D300,D301
files: ^src/
args: [--config=pyproject.toml]
Binary file added doc/source/QiboTN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doc/source/getting-started/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Getting started
===============


In this section we present the basic aspects of the Qibotn design and provide installation instructions.
Please visit the following sections to understand how ``qibotn`` works.

Expand Down
65 changes: 61 additions & 4 deletions doc/source/getting-started/quickstart.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
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.
In this section, we provide examples on how to use Qibotn to execute tensor network
simulation of quantum circuit. First, we show how to use the Cutensornet and Quimb
backends, while in a second moment we show a complete example of usage of the Quantum
Matcha Tea Backend.

Setting the backend
"""""""""""""""""""
Setting the backend with Cutensornet and Quimb
""""""""""""""""""""""""""""""""""""""""""""""

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.
Among the backends provided by Qibotn, we have 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.
These backend can be set using the following command line.

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

Expand Down Expand Up @@ -79,3 +85,54 @@ The following is a basic example to execute a two qubit circuit and print the fi

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


Using the Quantum Matcha Tea backend
""""""""""""""""""""""""""""""""""""

In the following we show an example of how the Quantum Matcha Tea backend can be
used to execute a quantum circuit::

# We need Qibo to setup the circuit and the backend
from qibo import Circuit, gates
from qibo.models.encodings import ghz_state
from qibo.backends import construct_backend

# We need Quantum Matcha Tea to customize the tensor network simulation
from qmatchatea import QCConvergenceParameters

# Set the number of qubits
nqubits = 40

# Construct a circuit preparing a Quantum Fourier Transform
circuit = ghz_state(nqubits)

# Construct the backend
backend = construct_backend(backend="qibotn", platform="qmatchatea")

# Customize the low-level backend preferences according to Qibo's formalism
backend.set_device("/CPU:1")
backend.set_precision("double")

# Customize the tensor network simulation itself
backend.configure_tn_simulation(
ansatz = "MPS",
convergence_params = QCConvergenceParameters(max_bond_dimension=50, cut_ratio=1e-6)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This QCConvergenceParameters comes from matcha right? I would argue that it would be better not to ask a qibo user to deal with matcha objects ideally. Maybe we could have an analogue qibo object that interfaces to the different convergence parameters of the backends, the `QCConvergenceParameters`` in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I can document the configure_tn_simulation listing the possible arguments which can be used to setup the QCConvergenceParameters.
Something like:

 def configure_tn_simulation(
        self,
        ansatz: str = "MPS",
        **convergence_params=None,
    ):
        """Configure TN simulation given Quantum Matcha Tea interface.

        Args:
            ansatz (str): tensor network ansatz. It can be  tree tensor network "TTN"
            or Matrix Product States "MPS" (default).
            **convergence_params: all the supported custom arguments of <link to matcha function>.
        """

       conv_params = QCConvergenceParameters(**convergence_params)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, I still think it would be better not to expose to the user objects that are not qibo's

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about now? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect thanks!

)

# Execute the tensor network simulation
outcome = backend.execute_circuit(
circuit = circuit,
nshots=1024,
)

# Print some results
print(outcome.probabilities())
# Should print something like: {'0000000000000000000000000000000000000000': 0.5000000000000001, '1111111111111111111111111111111111111111': 0.5000000000000001}
MatteoRobbiati marked this conversation as resolved.
Show resolved Hide resolved
print(outcome.frequencies())
# Should print something like: {'0000000000000000000000000000000000000000': 488, '1111111111111111111111111111111111111111': 536}


By default, the simulator is choosing a specific method to compute the probabilities,
and for further information we recommend the user to refer to our High-Level-API
docstrings: :doc:`/api-reference/qibotn.backends`.
55 changes: 40 additions & 15 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,54 @@
What is QiboTN?
===============

QiboTN is the dedicated `Qibo <https://github.com/qiboteam/qibo>`_ backend to support large-scale simulation of quantum circuits and acceleration.
Qibotn is an high-level library which integrates tensor network simulation within
the `Qibo <https://github.com/qiboteam/qibo>`_ ecosystem.

Supported Computation:
If you are familiar with Qibo, you will be well aware of the modularity we provide
through the use of our backends: after building a specific algorithm or quantum
circuit, any of our backends can be selected to perform operations on the
desired hardware (classical or quantum).

- Tensornet (TN)
- Matrix Product States (MPS)
Here, we extend this modularity to one of the most famous quantum inspired simulation
technique.

Tensor Network contractions to:
We do this by relying on well-known and maintained packages, and integrating their
operation into our own dedicated backends.

- dense vectors
- expecation values of given Pauli string
.. image:: QiboTN.png

The supported HPC configurations are:

- single-node CPU
- single-node GPU or GPUs
- multi-node multi-GPU with Message Passing Interface (MPI)
- multi-node multi-GPU with NVIDIA Collective Communications Library (NCCL)
As shown in the figure above, we currently support three different backends, which
correspond to the three mentioned packages:
- `cuQuantum <https://github.com/NVIDIA/cuQuantum>`_: an NVIDIA SDK of optimized libraries and tools for accelerating quantum computing workflows (we refer to the specific `Cutensornet <https://docs.nvidia.com/cuda/cuquantum/latest/cutensornet/index.html>`_ library);
- `quimb <https://quimb.readthedocs.io/en/latest/>`_: an easy but fast python library for ‘quantum information many-body’ calculations, focusing primarily on tensor networks;
- `Quantum Matcha Tea <https://www.quantumtea.it/>`_: a logical quantum computer emulator powered by matrix product states.

.. warning::

There are currently two ways to use the three backends (`qmatchatea` is
slightly different from the others), but we are working to standardize the interface.

Thanks to the mentioned packages, we currently support some tensor network ansatze:
Matrix Product States (MPS) on any mentioned backend, Tree Tensor Networks (TTN)
through the Quantum Matcha Tea backend and a more general Tensor Network (TN) ansatz through
Cutensornet and Quimb.

Supported simulation features
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We support Tensor Network contractions to:

- dense vectors (all the backends)
- expecation values of given Pauli string (Cutensornet and Qmatchatea)

The supported HPC configurations are:

Currently, the supported tensor network libraries are:
- single-node CPU through Quimb and Qmatchatea
- single-node GPU or GPUs through Cutensornet and Qmatchatea
- multi-node multi-GPU with Message Passing Interface (MPI) through Cutensornet
- multi-node multi-GPU with NVIDIA Collective Communications Library (NCCL) through Cutensornet

- `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 Down
Binary file added examples/qmatchatea_intro/qibojit_errs.npy
Binary file not shown.
Binary file added examples/qmatchatea_intro/qibojit_times.npy
Binary file not shown.
Binary file added examples/qmatchatea_intro/qmatcha_errs.npy
Binary file not shown.
Binary file added examples/qmatchatea_intro/qmatcha_times.npy
Binary file not shown.
Loading