Package: quantum-gates
Noisy Quantum GatesImplementation of the Noisy Quantum Gates model, published inDi 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.DocumentationsThe documentation for Noisy Quantum Gates can be accessed on the websiteRead the Docs.How to installRequirementsThe Python version should be 3.9 or later. Find your Python version by typingpythonorpython3in the CLI.
We recommend using the repo together with anIBM Quantum Labaccount, as it necessary for circuit compilation with Qiskit in many cases.Installation as a userThe library is available on the Python Package Index (PyPI) withpip install quantum-gates.Installation as a contributorFor users who want to have control over the source code, we recommend the following installation. Clone the repository
fromGithub, create a new virtual environment, and activate the
environment. Then you can build the wheel and install it with the package manager of your choice as described in the
sectionHow to contribute. This will install all dependencies in your virtual environment,
and install a working version of the library.QuickstartExecute the following code in a script or notebook. Add your IBM token to by defining it as the variable IBM_TOKEN = "your_token". 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.# Standard librariesimportnumpyasnpimportjson# QiskitfromqiskitimportQuantumCircuit,transpilefromqiskit.visualizationimportplot_histogram# Own libraryfromquantum_gates.simulatorsimportMrAndersonSimulatorfromquantum_gates.gatesimportstandard_gatesfromquantum_gates.circuitsimportEfficientCircuitfromquantum_gates.utilitiesimportDeviceParametersfromquantum_gates.utilitiesimportsetup_backendIBM_TOKEN="<your_token>"We create a quantum circuit with Qiskit.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 withconfig={"backend":{"hub":"ibm-q","group":"open","project":"main","device_name":"ibmq_manila"},"run":{"shots":1000,"qubits_layout":[0,1],"psi0":[1,0,0,0]}}... and setup the Qiskit backend used for the circuit transpilation.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.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 ...sim=MrAndersonSimulator(gates=standard_gates,CircuitClass=EfficientCircuit)t_circ=transpile(circ,backend,scheduling_method='asap',initial_layout=qubits_layout,seed_transpiler=42)probs=sim.run(t_qiskit_circ=t_circ,qubits_layout=qubits_layout,psi0=np.array(run_config["psi0"]),shots=run_config["shots"],device_param=device_param_lookup,nqubit=2)counts_ng={format(i,'b').zfill(2):probs[i]foriinrange(0,4)}... and analyse the result.plot_histogram(counts_ng,bar_labels=False,legend=['Noisy Gates simulation'])UsageWe recommend to read theoverviewof the documentation as a 2-minute preparation.ImportsThere are two ways of importing the package. 1) If you installed the code with pip, then the imports are simply of the form seen in theQuickstart.fromquantum_gates.simulatorsimportMrAndersonSimulatorfromquantum_gates.gatesimportstandard_gatesfromquantum_gates.circuitsimportEfficientCircuitfromquantum_gates.utilitiesimportDeviceParameters,setup_backendIf you use the source code directly and develop within the repository, then the imports becomefromsrc.quantum_gates._simulation.simulatorimportMrAndersonSimulatorfromsrc.quantum_gates._gates.gatesimportstandard_gatesfromsrc.quantum_gates._simulation.circuitimportEfficientCircuitfromsrc.quantum_gates._utility.device_parametersimport(DeviceParameters,setup_backend)FunctionalityThe main components are thegates,
and thesimulator.
One can configure the gates with differentpulse shapes,
and the simulator with differentcircuit classesandbackends. The circuit classes use a specific
backend for the statevector simulation.
TheEfficientBackendhas the same functionality as
theStandardBackend, but is much more performant
thanks to optimized tensor contraction algorithms. We also provide variousquantum algorithmsas 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 TestsWe 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 create a script token.py in the configuration folder. You can check the token_template.py
for reference. Make sure that your token is active and you have accepted all license agreement with IBM in your IBM
account.How to contributeContributions 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 thePEP 8 style guide, and add comments whenever it helps. The correspondingauthorsare happy to support you.BuildYou 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 commandpython3 -m build --sdist --wheel .and navigate to the distribution withcd dist.
Uselsto display the name of the wheel, and runpip install <filename>.whlwith the correct filename.
Now you can use your version of the library.CreditsPlease cite the work using the following BibTex entry:@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}
}AuthorsThis 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 CesaMichele Grossi (michele.grossi@cern.ch)Sandro DonadiAngelo BassiRoman Wixinger (roman.wixinger@gmail.com)