package containing utility methods for qiskit like result parsing and instruction insertion for circuits
Project description
qiskit-utils
qiskit-utils is a library containing utility, quality of life methods for qiskit.
current methods
- parsing results
- parsing counts
- inserting instructions and gates into circuit (in any location not just append the gate to the circuit)
Inserting instructions
from qiskit_utils import insert_instruction
instruction = Measure()
insert_instruction(circuit, instruction, (circuit.qubits[0],), (circuit.clbits[1], ), index)
QuantumCircuitEnhanced
from qiskit.circuit.library import iSwapGate
from qiskit_utils import QuantumCircuitEnhanced
qc = QuantumCircuitEnhanced(2)
qc.insert(iSwapGate(), (0, 1), (,), index)
Result parsing
parse_result method allows to find the counts for each specific qubit individually (and allows for easy access to check counts for that one specific qubit, independent of the other qubit states)
qc = QuantumCircuit(1, 1)
qc.x(0)
qc.measure(0, 0)
backend = Aer.get_backend("aer_simulator")
transpiled_circuit = transpile(qc, backend)
result = backend.run(transpiled_circuit).result()
parsed_counts = parse_result(result, qc)
# parsed_counts = {0: {'0': 0, '1': 1024}}
2 return types are possible, with using the flag indexed_results=True resulting directory keys (the most upper level) will be indexes of qubits (indexes will be same as in qc.qubits), with the flag set to false qubits will be returned indexed by the qubit object itself (can be received either from qc.qubits[i] or QuantumRegister()[i])
Result parsing with counts
qc = QuantumCircuit(2)
creg1 = ClassicalRegister(1)
creg2 = ClassicalRegister(1)
qc.add_register(creg1)
qc.add_register(creg2)
qc.x(0)
qc.measure(0, creg1[0])
qc.measure(1, creg2[0])
backend = Aer.get_backend("aer_simulator")
transpiled_circuit = transpile(qc, backend)
result = backend.run(transpiled_circuit).result()
parsed_counts = parse_counts(result, qc)
# parsed_counts = {"10": 1024} while the get_counts from qiskit would return {"0 1": 1024}
Note, qubits that had no measurements found for them are marked as - in the bitstring
More examples
examples of usage can be found in a testing library qiskit-check
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file qiskit_utils-1.2.1.tar.gz.
File metadata
- Download URL: qiskit_utils-1.2.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
851d6ca411b1aaa7884ddd641b2e429f78fc4de8985f46d7b2816fff0f3af39d
|
|
| MD5 |
2117c75d2787678d6dc11e9b0fda3544
|
|
| BLAKE2b-256 |
e20271743b9f4145235a619b0056115dea7dbf03937d33b3ced374b1ffa240c4
|