Tool for analyzing quantum circuits
Project description
QBenchAnalyzer
A tool to generate a set of metrics for quantum circuits.
How to use it
You can find an example of usage in the demo.py file. In general, you only want to use the
generate_metrics method. Here is a little example of how to use it.
from QBenchAnalyzer import generate_metrics
from qiskit import QuantumCircuit
circuit = "qaoa_vanilla_04.qasm"
qc = QuantumCircuit.from_qasm_file(circuit)
metrics = generate_metrics(qc)
print(metrics)
and, if you used the same circuit as the included in the repository, this will return the following set of metrics:
{'qubit_connections': {2: {0, 1, 3}, 3: {0, 1, 2}, 1: {0, 2, 3}, 0: {1, 2, 3}}, 'n_qubits': 4,
'n_2gates_x_qubit': {2: 6, 3: 6, 1: 6, 0: 6}, 'n_gates': 26, 'depth': 17, 'avg_2gates_x_qubit': 6.0,
'n_consecutive_2_gates': 3, 'n_2_gates': 12, 'n_2gates_critical_path': 10, 'entanglement_ratio': 0.46153846153846156,
'critical_depth': 0.8333333333333334, 'parallelism': 0.17647058823529407, 'program_communication': 1.0,
'entanglement_variance': 0.0}
Alternatively, you can generate predefined images using the method analyze_circuit_group_structural, which will generate
an analysis of the metrics for a group of circuits. For doing so, you will need to implement a class that
implements the ICircuitGenerator interface and use it to tell the method which circuits will you want to use.
Here is an example of a functional script for calculating the metrics of the QFT circuits using the circuits between 5 and
10 qubits:
# Importing all the necesary stuff
from QBenchAnalyzer.circuit_generator import ICircuitGenerator
from QBenchAnalyzer import analyze_circuit_group_structural
from qiskit import QuantumCircuit
# Creating a class that could read all the circuits
class CircuitGenerator(ICircuitGenerator): # It is important that implement the ICircuitGenerator
def __init__(self, name, file_name):
super().__init__(name) # Title of the image
self.file_name = file_name # File name of the circuits to read
def generate_qiskit_circuit(self, number_of_qubits):
# Calculate the path of the circuit with 'number_of_qubits' for reading
file_path = f"./test/{self.file_name}_{number_of_qubits}.qasm"
# Return the circuit as a QuantumCircuit object
return QuantumCircuit.from_qasm_file(file_path)
# Call this method to generate the graphic image of all metrics of one circuit group
analyze_circuit_group_structural(
CircuitGenerator("Testing QFT", "qft"), # Instance of the circuit generator
5, # Smallest number of qubits of the circuit group to read
10, # Bigger number of qubits of the circuit group to read
"example.jpg", # Name for the output image
"./images/" # Path were the output should be store
)
Executing the example will output an image that will look like the following:
And the final working directory tree will look like:
.
├── images
│ ├── example.jpg
├── test
│ ├── qft_5.qasm
│ ├── qft_6.qasm
│ ├── qft_7.qasm
│ ├── qft_8.qasm
│ ├── qft_9.qasm
│ └── qft_10.qasm
├── main.py
Contributing
If you want to make changes, it is needed to test all the changes in local before a merge request. To do it, it is needed to install the local changes first, and then run the test. You can use the following commands as a guide:
pip install .
python3 -m pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qbenchanalyzer-0.0.3a0.tar.gz.
File metadata
- Download URL: qbenchanalyzer-0.0.3a0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad3b8bb21154e33ceb88e16820c285b1add1eff61707018754c7e6e8e3d76164
|
|
| MD5 |
1469cad3fd8754c4d55f5415bea79b12
|
|
| BLAKE2b-256 |
a108ff84cd220c947949d06408e7723682dc74fafa254d54f219bd6875c1a31f
|
File details
Details for the file qbenchanalyzer-0.0.3a0-py3-none-any.whl.
File metadata
- Download URL: qbenchanalyzer-0.0.3a0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9aa9b5938105627cdc614780a9928f71223bc75ad00890b5656d834f7e407dcb
|
|
| MD5 |
4808ef73f81138cfded911327e5a19ac
|
|
| BLAKE2b-256 |
8540dd2f448e98e3234bb6c8af9b07167ef1321716c8200f1393b56182ecc396
|