C2QA / bosonic-qiskit

Extension of Qiskit to support hybrid boson-qubit simulations for the NQI C2QA effort.
BSD 2-Clause "Simplified" License
46 stars 11 forks source link

Average photon number function #97

Closed liu-zixiong closed 1 year ago

liu-zixiong commented 1 year ago

Hi Tim and Kevin,

Just thought that adding a function specifically for computing average photon number for a given qumode state would be helpful for the repo. The docstring for the function is copied below. Let me know what you think!

def avg_photon_num(state, decimals: int=2):
    """Returns average photon number of state using the number operator.

    Args:
        state (Statevector or DensityMatrix): State to operate on
        decimals: Determines precision of calculation

    Returns:
        float: Average photon number to specified precision
    """