Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
4.83k stars 2.29k forks source link

WIP: Add base representation of `SparseObservable` #12671

Open jakelishman opened 5 days ago

jakelishman commented 5 days ago

Summary

This adds the very base representation of SparseObservable, including the lowest-level constructor from Python space and the ability to view the data buffers. It does not add any of the means to calculate with it, nor any of the high-level interfaces to construction.

This WIP commit will be amended to at least add documentation and tests of the contents.

Details and comments

This is the beginnings of the implementation of Qiskit/RFCs#74, and subject to change based on decisions made there.

A current simple example of what works with the PR:

import numpy as np
from qiskit.quantum_info import SparseObservable

# Using the copy-in constructor to make the Z_0 + Z_1 + Z_2 + ... operator
# by manually providing the data buffers.
num_qubits = 100
terms = np.full((num_qubits,), SparseObservable.BitTerm["+"], dtype=np.uint8)
indices = np.arange(num_qubits, dtype=np.uint32)
coeffs = np.ones((num_qubits,), dtype=complex)
boundaries = np.arange(num_qubits + 1, dtype=np.uintp)
# This copies out of the buffers, because we need the base allocations to be
# owned by Rust space.  For performance, this will not check the values of the
# input arrays for validity.
so = SparseObservable.from_raw_parts(num_qubits, coeffs, terms, indices, boundaries)

print(so.bit_terms)

This PR depends on #12669.

coveralls commented 5 days ago

Pull Request Test Coverage Report for Build 9684156922

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/euler_one_qubit_decomposer.rs 3 9 33.33%
crates/accelerate/src/two_qubit_decompose.rs 3 9 33.33%
crates/circuit/src/circuit_data.rs 82 93 88.17%
crates/circuit/src/slice.rs 106 129 82.17%
crates/accelerate/src/sparse_observable.rs 54 399 13.53%
<!-- Total: 251 642 39.1% -->
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 5 92.37%
crates/qasm2/src/parse.rs 12 97.15%
<!-- Total: 18 -->
Totals Coverage Status
Change from base Build 9683280067: -0.4%
Covered Lines: 63894
Relevant Lines: 71496

💛 - Coveralls