Skip to content

Type annotations in reporting - #720

Open
nkoskelo wants to merge 53 commits into
developfrom
type_annotations_in_reporting
Open

Type annotations in reporting#720
nkoskelo wants to merge 53 commits into
developfrom
type_annotations_in_reporting

Conversation

@nkoskelo

Copy link
Copy Markdown
Contributor

Improving maintainability by adding more type annotations to the reporting modules of the code.

@nkoskelo
nkoskelo requested review from a team as code owners February 27, 2026 18:14
@nkoskelo
nkoskelo marked this pull request as draft March 2, 2026 18:50
@nkoskelo
nkoskelo marked this pull request as ready for review April 9, 2026 17:02
@nkoskelo
nkoskelo requested review from a team, pcwysoc and tjproct as code owners April 9, 2026 17:02
@coreyostrove
coreyostrove requested a review from rileyjmurray May 19, 2026 17:47
Comment thread pygsti/protocols/stability.py Outdated

@ndsieki ndsieki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many type annotations are missing for function parameters. I've marked them explicitly in many cases.

Most functions/methods are also missing an annotation of the return type. I only marked the first few instances of this missing return type; in general, it should be added for every function/method, including those where I didn't leave a comment.

I've marked every case where I observed that the provided type annotation was incorrect. There were not many of those cases.

Comment thread pygsti/data/datasetconstruction.py Outdated
Comment thread pygsti/protocols/freeformsim.py Outdated
Comment thread pygsti/protocols/freeformsim.py Outdated
Comment thread pygsti/protocols/freeformsim.py Outdated
Comment thread pygsti/protocols/freeformsim.py Outdated
Comment thread pygsti/report/reportables.py Outdated


def entanglement_fidelity(a, b, mx_basis):
def entanglement_fidelity(a, b, mx_basis: BasisLike):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a type annotation for a and b.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply this comment to all other functions foo(a, b, mx_basis: BasisLike).

Comment thread pygsti/report/reportables.py Outdated


def errorgen_and_projections(errgen, mx_basis):
def errorgen_and_projections(errgen, mx_basis: BasisLike):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add type annotation for errgen.

Comment thread pygsti/report/reportables.py Outdated


def vec_as_stdmx(vec, mx_basis):
def vec_as_stdmx(vec, mx_basis: BasisLike):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a type annotation for vec.

Comment thread pygsti/report/reportables.py Outdated


def vec_as_stdmx_eigenvalues(vec, mx_basis):
def vec_as_stdmx_eigenvalues(vec, mx_basis: BasisLike):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a type annotation for vec.

Comment thread pygsti/protocols/freeformsim.py Outdated
@sandialabs sandialabs deleted a comment from ndsieki Jul 1, 2026

@ndsieki ndsieki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of comments because there are a lot of files. I found minimal cases where an annotation was actually incorrect. There are cases where the annotation is imprecise (e.g., str instead of Literal[...], or Any when a type is clarified in the docstring) and I've indicated those cases. I don't fully trust the docstrings for some functions but I've used them as a point of reference where relevant.

Comment thread pygsti/data/datasetconstruction.py Outdated
Comment thread pygsti/data/datasetconstruction.py Outdated
Comment thread pygsti/extras/drift/stabilityanalyzer.py Outdated
Comment thread pygsti/protocols/gst.py Outdated
Comment thread pygsti/protocols/gst.py Outdated
Comment thread pygsti/report/workspacetables.py Outdated

def __init__(self, ws, xs, circuits_by_x, model_by_x, dataset_by_x, objfn_builder='logl',
x_label='L', np_by_x=None, comm=None, wildcard=None, mdc_stores=None):
def __init__(self, ws: _Workspace, xs: Sequence[Any], circuits_by_x: Sequence[Union[_CircuitList, Sequence[_Circuit]]], model_by_x: Sequence[Optional[_Model]], dataset_by_x: Union[_DataSet, Sequence[_DataSet]], objfn_builder: Union[str, _ObjectiveFunctionBuilder] = 'logl',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For xs, docstring indicates Sequence[int]; please update the annotation if docstring is correct.

objfn_builder has literal options in the docstring as well, please incorporate if appropriate.

Comment thread pygsti/report/workspacetables.py Outdated
"""

def __init__(self, ws, circuit_lists, titles, num_cols=1, common_title=None):
def __init__(self, ws: _Workspace, circuit_lists: Sequence[Any], titles: Union[str, Sequence[str]], num_cols: int = 1, common_title: Optional[str] = None) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the circuit_lists annotation with the more precise annotation found in other classes in this file.

Comment thread pygsti/report/workspacetables.py Outdated
def __init__(self, ws, metric, models, target_models, titles,
rowtitles=None, table_title=None, op_label=None,
confidence_region_info=None):
def __init__(self, ws: _Workspace, metric: AVAILABLE_METRICS, models: Sequence[Any], target_models: Sequence[Any], titles: Sequence[str],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the Any type annotations with more precise Model annotations.

Comment thread pygsti/report/workspacetables.py Outdated

def __init__(self, ws, model_dim, projection_type,
projection_basis):
def __init__(self, ws: _Workspace, model_dim: int, projection_type: str,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add literal type annotations for projection_type and projection_basis as found in the docstring.

Comment thread pygsti/report/workspacetables.py Outdated
"""

def __init__(self, ws, profiler, sort_by="time"):
def __init__(self, ws: _Workspace, profiler: Optional[_Profiler], sort_by: str = "time") -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add Literal annotation for sort_by following the docstring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants