quantum-gates
Noisy Quantum Gates model for simulating the noise of quantum devices.
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: aps.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.7%) to scientific vocabulary
Keywords
Repository
Noisy Quantum Gates model for simulating the noise of quantum devices.
Basic Info
- Host: GitHub
- Owner: CERN-IT-INNOVATION
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://quantum-gates.readthedocs.io/en/latest/
- Size: 424 KB
Statistics
- Stars: 18
- Watchers: 2
- Forks: 6
- Open Issues: 8
- Releases: 2
Topics
Metadata Files
README.md
Noisy Quantum Gates

Implementation of the Noisy Quantum Gates model, published in Di Bartolomeo, 2023. It is a novel method to simulate the noisy behaviour of quantum devices by incorporating the noise directly in the gates, which become stochastic matrices.
Documentations
The documentation for Noisy Quantum Gates can be accessed on the website Read the Docs.
How to install
Requirements
The Python version should be 3.9 or later. Find your Python version by typing python or python3 in the CLI.
We recommend using the repo together with an IBM Quantum Lab account, as it necessary for circuit compilation with Qiskit in many cases.
Installation as a user
The library is available on the Python Package Index (PyPI) with pip install quantum-gates.
Installation as a contributor
For users who want to have control over the source code, we recommend the following installation.
- Clone the repository:
bash
git clone https://github.com/CERN-IT-INNOVATION/quantum-gates.git
- Navigate to the project directory:
bash
cd quantum_gates
- Create virtual environment
You can either use your IDE to set this up automatically or do it manually in the CLI.
bash
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
This saves your environment from pollution.
- Install the package in editable mode.
bash
pip install -e .
This command installs the package in editable mode, allowing you to work directly with the source code. Any changes you
make will be immediately available without the need to reinstall the package.
Quickstart
You can find this quickstart implemented in the tutorial notebook here.
Execute the following code in a script or notebook. Add your IBM token to by defining it as the variable IBMTOKEN = "yourtoken". Optimally, you save your token in a separate file that is not in your version control system, so you are not at risk of accidentally revealing your access token.
```python
Standard libraries
import numpy as np import json
Qiskit
from qiskit import QuantumCircuit, transpile from qiskit.visualization import plot_histogram
Own library
from quantumgates.simulators import MrAndersonSimulator
from quantumgates.gates import standardgates
from quantumgates.circuits import EfficientCircuit, BinaryCircuit
from quantumgates.utilities import DeviceParameters
from quantumgates.utilities import setupbackend
IBMTOKEN = "
python
circ = QuantumCircuit(2,2)
circ.h(0)
circ.cx(0,1)
circ.barrier(range(2))
circ.measure(range(2),range(2))
circ.draw('mpl')
We load the configuration from a json file or from code with
python
config = {
"backend": {
"hub": "ibm-q",
"group": "open",
"project": "main",
"device_name": "ibm_kyiv"
},
"run": {
"shots": 1000,
"qubits_layout": [0, 1],
"psi0": [1, 0, 0, 0]
}
}
... and setup the Qiskit backend used for the circuit transpilation.
python
backend_config = config["backend"]
backend = setup_backend(Token=IBM_TOKEN, **backend_config)
run_config = config["run"]
This allows us to load the device parameters, which represent the noise of the quantum hardware.
python
qubits_layout = run_config["qubits_layout"]
device_param = DeviceParameters(qubits_layout)
device_param.load_from_backend(backend)
device_param_lookup = device_param.__dict__()
Last, we perform the simulation ... ```python sim = MrAndersonSimulator(gates=standard_gates, CircuitClass=EfficientCircuit)
tcirc = transpile( circ, backend, schedulingmethod='asap', initiallayout=qubitslayout, seed_transpiler=42 )
probs = sim.run( tqiskitcirc=tcirc, qubitslayout=qubitslayout, psi0=np.array(runconfig["psi0"]), shots=runconfig["shots"], deviceparam=deviceparamlookup, nqubit=2, level_opt = 0)
``` ... and analyse the result.
python
plot_histogram(probs, bar_labels=False, legend=['Noisy Gates simulation'])
If you want to use a non-linear topology you must use the BinaryCircuit and slightly modify the code. First of all we modify the qubit layout to match the topology of the device.
python
config = {
"run": {
"shots": 1000,
"qubits_layout": [0, 14],
"psi0": [1, 0, 0, 0]
}
}
Then also the command to import the parameter device has to change in order to import all the information of all the qubits up to the one with the max indices.
python
device_param = DeviceParameters(list(np.arange(max(qubits_layout)+1)))
device_param.load_from_backend(backend)
device_param_lookup = device_param.__dict__()
Last, we perform the simulation ... ```python sim = MrAndersonSimulator(gates=standard_gates, CircuitClass=BinaryCircuit)
tcirc = transpile( circ, backend, schedulingmethod='asap', initiallayout=qubitslayout, seed_transpiler=42 )
probs = sim.run( tqiskitcirc=tcirc, qubitslayout=qubitslayout, psi0=np.array(runconfig["psi0"]), shots=runconfig["shots"], deviceparam=deviceparamlookup, nqubit=2, level_opt = 4)
``` ... and analyse the result.
python
plot_histogram(probs, bar_labels=False, legend=['Noisy Gates simulation'])
Remember that the ouput of the simulator follows the Big-Endian order, if you want to switch to Little-Endian order, which is the standard for Qiskit, you can use the command
```python from quantumgates.utilities import fixcounts
nmeasuredqubit = 2 probslittleendian = fixcounts(probs, nmeasuredqubit) plothistogram(probslittleendian, bar_labels=False, legend=['Noisy Gates simulation']) ```
Usage
We recommend to read the overview of the documentation as a 2-minute preparation. You can import the package modules as shown in the Quickstart:
python
from quantum_gates.simulators import MrAndersonSimulator
from quantum_gates.gates import standard_gates
from quantum_gates.circuits import EfficientCircuit
from quantum_gates.utilities import DeviceParameters, setup_backend
Functionality
The main components are the gates, and the simulator. One can configure the gates with different pulse shapes, and the simulator with different circuit classes and backends. The circuit classes use a specific backend for the statevector simulation. The EfficientBackend has the same functionality as the StandardBackend, but is much more performant thanks to optimized tensor contraction algorithms. We also provide various quantum algorithms as circuits, and scripts to run the circuits with the simulator, the IBM simulator, and a real IBM backend. Last, all functionality is unit tested and one can get sample code from the unit tests.
Unit Tests
We recommend running the unit tests once you are finished with the setup of your environment. As some tests need access to IBM devices, you have to follow the steps outlined in token.py. Make sure that your token is active and you have accepted all license agreement with IBM in your IBM account. Before you run the tests, make sure that the device you are testing with (the on set in tests/simulation/testandersonsimulator.py) is available in your account and the device parameters are prepared in the tests/utility/device_parameters folder. In the future we might upgrade the tests and mock these dependencies.
Afer activating your virtual environment, you can run the tests from root with
bash
python -m "pytest"
Using this command instead of just typing pytest will make sure that you are using
the right Python version to run pytest. You can also just run a subset of the test, for example:
bash
python -m pytest -k test_gates_noiseless_cnot_inv
How to contribute
Contributions are welcomed and should apply the usual git-flow: fork this repo, create a local branch named
'feature-...'. Commit often to ensure that each commit is easy to understand. Name your commits
'[feature-...] Commit message.', such that it possible to differentiate the commits of different features in the
main line. Request a merge to the mainline often. Contribute to the test suite and verify the functionality with the unit tests when using a different Python version or dependency versions. Please remember to follow the
PEP 8 style guide, and add comments whenever it helps. You can run the linter
with pylint .. The corresponding authors are happy to support you.
Build
You may also want to create your own distribution and test it. Navigate to the repository in your CLI of choice.
Build the wheel with the command python3 -m build --sdist --wheel . and navigate to the distribution with cd dist.
Use ls to display the name of the wheel, and run pip install <filename>.whl with the correct filename.
Now you can use your version of the library.
Building the documentation
The documentation for Noisy Quantum Gates is built using Sphinx and is hosted on ReadTheDocs. If you wish to build and view the documentation locally, follow these steps:
- Navigate to the
docsdirectory:
From the root of the project, navigate to the docs folder:
bash
cd docs
- Install the documentation requirements:
bash
pip install -r requirements.txt
Note: It's recommended to perform this step in your virtual environment.
- Build the HTML documentation:
Use the make command to build the HTML version of the documentation:
bash
make html
- View and check the documentation locally
Open the generated index.html file in your web browser to view the documentation:
bash
open build/html/index.html # On macOS
xdg-open build/html/index.html # On Linux
start build\html\index.html # On Windows (Command Prompt)
Or manually navigate to the build/html directory and open index.html with your preferred web browser.
Credits
Please cite the work using the following BibTex entry:
text
@article{PhysRevResearch.5.043210,
title = {Noisy gates for simulating quantum computers},
author = {Di Bartolomeo, Giovanni and Vischi, Michele and Cesa, Francesco and Wixinger, Roman and Grossi, Michele and Donadi, Sandro and Bassi, Angelo},
journal = {Phys. Rev. Res.},
volume = {5},
issue = {4},
pages = {043210},
numpages = {19},
year = {2023},
month = {Dec},
publisher = {American Physical Society},
doi = {10.1103/PhysRevResearch.5.043210},
url = {https://link.aps.org/doi/10.1103/PhysRevResearch.5.043210}
}
Authors
This project has been developed thanks to the effort of the following people:
- Giovanni Di Bartolomeo (dibartolomeo.giov@gmail.com)
- Michele Vischi (vischimichele@gmail.com)
- Francesco Cesa
- Michele Grossi (michele.grossi@cern.ch)
- Sandro Donadi
- Angelo Bassi
- Paolo Da Rold
- Roman Wixinger (roman.wixinger@gmail.com)
Owner
- Name: CERN-IT-INNOVATION
- Login: CERN-IT-INNOVATION
- Kind: organization
- Repositories: 6
- Profile: https://github.com/CERN-IT-INNOVATION
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it as below." authors: - family-names: "Di Bartolomeo" given-names: "Giovanni" orcid: "https://orcid.org/0000-0002-1792-7043" - family-names: "Vischi" given-names: "Michele" orcid: "https://orcid.org/0000-0002-5724-7421" - family-names: "Wixinger" given-names: "Roman" orcid: "https://orcid.org/0000-0001-7113-4370" - family-names: "Grossi" given-names: "Michele" orcid: "https://orcid.org/0000-0003-1718-1314" - family-names: "Donadi" given-names: "Sandro" - family-names: "Da Rold" given-names: "Paolo" - family-names: "Bassi" given-names: "Angelo" orcid: "https://orcid.org/0000-0001-7500-387X" title: "Noisy gates for simulating quantum computers" version: 2.2 doi: "10.1103/PhysRevResearch.5.043210" date-released: 2023-12-06 url: "https://link.aps.org/doi/10.1103/PhysRevResearch.5.043210"
GitHub Events
Total
- Create event: 4
- Release event: 2
- Issues event: 4
- Watch event: 8
- Delete event: 1
- Issue comment event: 12
- Push event: 8
- Pull request review comment event: 24
- Pull request review event: 11
- Pull request event: 8
- Fork event: 2
Last Year
- Create event: 4
- Release event: 2
- Issues event: 4
- Watch event: 8
- Delete event: 1
- Issue comment event: 12
- Push event: 8
- Pull request review comment event: 24
- Pull request review event: 11
- Pull request event: 8
- Fork event: 2
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 12
- Total Committers: 2
- Avg Commits per committer: 6.0
- Development Distribution Score (DDS): 0.083
Top Committers
| Name | Commits | |
|---|---|---|
| romanwixinger | r****r@g****m | 11 |
| Michele Grossi | 3****M@u****m | 1 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 17
- Total pull requests: 8
- Average time to close issues: 3 months
- Average time to close pull requests: 13 days
- Total issue authors: 2
- Total pull request authors: 4
- Average comments per issue: 0.41
- Average comments per pull request: 0.75
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: 3 months
- Issue authors: 0
- Pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 1.5
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- romanwixinger (14)
- 1ucian0 (2)
- fabiocfabini (1)
Pull Request Authors
- romanwixinger (7)
- paolodr98 (2)
- Yuvrajsinghspd09 (1)
- giodiba (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 76 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 8
- Total maintainers: 1
pypi.org: quantum-gates
Quantum Noisy Gates Simulation with Python
- Homepage: https://github.com/CERN-IT-INNOVATION/quantum-gates/
- Documentation: https://quantum-gates.readthedocs.io/
- License: MIT
-
Latest release: 2.2.0
published 9 months ago
Rankings
Maintainers (1)
Dependencies
- matplotlib *
- numpy >=1.22
- opt-einsum *
- pylatexenc *
- qiskit >=0.39.2
- scipy *
- matplotlib *
- numpy *
- opt-einsum *
- pylatexenc *
- qiskit ==0.39.2
- qiskit-ibm-provider *
- scipy *