Update Python API Doc Strings#3225
Merged
Merged
Conversation
billti
reviewed
May 20, 2026
billti
reviewed
May 20, 2026
billti
reviewed
May 20, 2026
billti
reviewed
May 20, 2026
billti
reviewed
May 20, 2026
billti
reviewed
May 20, 2026
billti
reviewed
May 20, 2026
billti
reviewed
May 20, 2026
amcasey
approved these changes
May 21, 2026
Co-authored-by: Andrew Casey <amcasey@users.noreply.github.com>
…ft/qdk into sccarda/UpdateDocStrings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update docstrings under
qdkand convertqsharpshims to deprecation docstringsFor a preview of the docs after this change see: https://review.learn.microsoft.com/en-us/python/qdk/qdk?view=qsharp-py&branch=pr-en-us-105
Note that we may want to omit the
qsharppackage documentation going forward as it is now a deprecated package.Summary
Following the migration of all package content from
qsharp(under source/pip/) intoqdk(under source/qdk_package/), this PR updates docstrings to reflect the new home of the code and fixes a large set of broken Sphinx cross-references throughout theqdkPython API documentation.The core changes are:
qsharp.*Sphinx cross-references inqdkdocstrings with the correctqdk.*paths.qdk._native.*cross-references at their public re-exports (and add public re-exports for three return types that didn't have one).# Deprecated: use qdk.X insteadcomments in theqsharpshim into proper module docstrings so the deprecation hint shows up inhelp(), IDE tooltips, and Sphinx autodoc.qdk/__init__.pydocstring to give an overview of the package, its core submodules, optional extras, and its relationship to the legacyqsharpshim.No behavioral changes. No exports were removed. While there are some public API changes that this work highlights would be good to have, this PR will focus on documentation changes and avoid making changes to the public API.
Public API additions
This PR previously made some changes to the public API that have been reverted. We want to avoid making those changes in this PR and a follow up team discussion and PR will be made to make the necessary changes.
Categories of change
qdkdocstrings — qsharp -> qdk path correctionsUpdated stale Sphinx cross-references that still pointed at the pre-migration
qsharp.*namespace::class:\~qsharp.X`,:func:`~qsharp.X`, and:attr:`~qsharp.X`references with the correct~qdk.X` paths in qdk/_interpreter.py, qdk/_context.py, qdk/openqasm/_circuit.py, qdk/cirq/init.py, qdk/qiskit/init.py, qdk/qiskit/jobs/qsjob.py, qdk/qiskit/jobs/qsjobset.py, and qdk/estimator/_estimator.py.from qsharp.X import Yandqsharp.compile("...")examples in docstrings to useqdk.*paths in qdk/openqasm/_compile.py, qdk/_interpreter.py, and qdk/qiskit/backends/neutral_atom_backend.py.qsharp.Resulttoqdk.Resultin qdk/cirq/_result.py.QSHARP_PYTHON_TELEMETRY) is unchanged for back-compat.qdkdocstrings — fully-qualified Sphinx cross-referencespy2docfx does not respect
__all__when resolving bare:class:/:func:references in docstrings, so module-level docstrings that listed unqualified names (like:func:\init``) produced unresolved xrefs. These have been fully qualified throughout:init,compile,circuitdocstrings.Context.__init__,Context.circuit,Context.compiledocstrings.qdkdocstrings — repointed away from privateqdk._native.*qdk._nativeis the Rust extension and is not documented, so cross-references to it are dead links. Each was repointed at its public re-export:qdk._native.QasmErrorqdk.openqasm.QasmErrorqdk._native.OutputSemanticsqdk.openqasm.OutputSemanticsqdk._native.ProgramTypeqdk.openqasm.ProgramTypeqdk._native.Circuitqdk.qsharp.CircuitThree additional return types had no public path at all, and have been re-exported from
qdk.qsharp:Circuit— return type ofqdk.qsharp.circuit().QirInputData— return type ofqdk.qsharp.compile()andqdk.openqasm.compile().Config— return type ofqdk.qsharp.init().These also unblock removing the
qdk._native.Xreferences in docstrings.qdkdocstrings — method/attribute self-reference cleanuppy2docfx does not generate per-method uids for the page describing a class, so
:meth:\result`from insideclass QsJob:doesn't resolve. Such self-references have been converted to plain backticks (e.g. ``result()` ``):qdkdocstrings — qre cleanup (no API change)Limited to docstring text fixes — public surface unchanged:
:param ctx (Context):annotations that should have read(ISAContext)in qdk/qre/_isa_enumeration.py.(Node | None)and(Node)parameter annotations that should have read(ISAQuery | None)/(ISAQuery)in qdk/qre/_instruction.py. TheNode | Noneform was also being mis-parsed by py2docfx into a malformed nested<xref:>.BindingNodereferences from the publicISATransform.binddocstring.Returns: _InstructionSourceNodeReference:/default (Optional[_InstructionSourceNodeReference])docstring annotations as descriptive prose since the type is private. The annotations on the actual method signatures are unchanged.A number of qre docs xrefs are still unresolved after this pass — see Known limitations of py2docfx below.
Top-level
qdk/__init__.pydocstringThe top-level docstring was rewritten to introduce QDK as the unified Python entry point, list the always-available core submodules (
qdk.qsharp,qdk.openqasm,qdk.simulation,qdk.estimator,qdk.qre,qdk.code), enumerate the convenience re-exports at the package root, list optional extras (qdk[azure],qdk[qiskit],qdk[cirq],qdk[jupyter]), and note the relationship to the deprecatedqsharpshim.qsharpshim — deprecation comments converted to docstringsAll ~37 shim files in source/pip/qsharp/ had a leading
# Deprecated: use qdk.X instead(or# Deprecation shim - delegates to qdk.X) comment. These have been converted to proper module docstrings of the form"""Deprecated. Use :mod:\qdk.X` instead."""` so the deprecation hint shows up in:help(qsharp.X)outputautodocextractionThe top-level pip/qsharp/init.py already has a proper docstring with migration guidance and a
DeprecationWarning; that file was not changed.Functional behavior of every shim is unchanged.
What was intentionally not changed
"qsharp.run","qsharp.compile", ...) — these are stable analytics identifiers.QSHARP_PYTHON_TELEMETRY,QSHARP_PYTHON_AI_KEY, ...) — public stable contract.QSharpError,QSharpBackend,QSharpApplication,__qsharp_class,_qsharp_value_to_python_value.qsharp.json— actual project manifest filename.qsharp_widgets,qsharp-widgets,qsharp-jupyterlab.Known limitations of py2docfx
A number of cross-references remain unresolved in the generated YAML output but are not source-fixable without changing the public API surface. They are noted here so reviewers don't expect this PR to address them:
Result,Pauli,Circuit,EstimatorResult,LogicalCounts,EstimationTableEntry,ConstraintBound) when the type is defined in or imported into the same module, regardless of__all__. The pages exist at the qualified paths; the xrefs from inside signature blocks just don't link.qdk.qsharp.CircuitGenerationMethod.ClassicalEvaletc. don't resolve.azure.quantum.*,cirq.*,pandas.DataFrame,matplotlib.figure.Figure,datetime.datetime, builtins likeint/bool/typing.*) — these need an xrefmap to be configured at the docs pipeline level.qdk.qre._Context,qdk.qre.TraceParameters,qdk.qre.Instruction,qdk.qre.models.ISA,qdk.qre.models.ISAContext,_InstructionSourceNodeReference— fixing each of these would require either renaming a private symbol to public, adding a TypeVar to__all__, or re-exporting a Rust-side type from additional submodules. Out of scope for this PR.Tooling note
The python-doc-gen tool that consumes these docstrings (py2docfx) has a roughly 30-minute build time, no local validation, no
--strictmode that flags unresolved xrefs as errors, and several known limitations (listed above) that mean a "valid Sphinx docstring" is not necessarily a "valid py2docfx docstring." Worth a discussion separately about whether to invest in a faster / more transparent doc generation toolchain (e.g. Sphinx + intersphinx withnitpickymode), since the current iteration loop is a significant productivity drag for any non-trivial docstring change.