Skip to content

[codex] Document pi_check behavior#15994

Draft
TSS99 wants to merge 1 commit intoQiskit:mainfrom
TSS99:codex/pi-check-docstring-10391-20260411
Draft

[codex] Document pi_check behavior#15994
TSS99 wants to merge 1 commit intoQiskit:mainfrom
TSS99:codex/pi-check-docstring-10391-20260411

Conversation

@TSS99
Copy link
Copy Markdown
Contributor

@TSS99 TSS99 commented Apr 10, 2026

Summary

  • document the actual formatting guarantees of pi_check for numeric, string, and ParameterExpression inputs
  • clarify how output and ndigits affect the rendered string
  • add focused tests for output modes, fallback formatting, string passthrough, and invalid output handling

Testing

  • source .venv-codex/bin/activate && python -m unittest test.python.circuit.test_tools

fixes #10391

AI tool used: OpenAI Codex (GPT-5)

@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Apr 10, 2026
Copy link
Copy Markdown
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

I believe this to have been made by an unsupervised LLM, but I am prepared to accept something like it, with modifications, provided a human comes in the loop to respond and to claim ownership of all the changes.

Please re-instate and complete the correct LLM disclosure from the PR template that was deleted.

I will not continue if this continues to be an unsupervised LLM.

Comment on lines +28 to 40
"""Return a string representation of ``inpt``, using simple ``pi`` forms when possible.

For numeric inputs, ``pi_check`` formats the real and imaginary parts independently. Within
``eps``, it prefers integer multiples of pi, powers of pi from ``pi**2`` through ``pi**4``
(except for ``output="qasm"``), and reduced fractions of the form ``n*pi/d`` or
``n/(d*pi)`` with numerators and denominators up to :data:`MAX_FRAC`. If none of those
patterns match, the value falls back to ordinary numeric formatting; ``ndigits`` only affects
this fallback formatting.

String inputs are returned unchanged. For :class:`~qiskit.circuit.ParameterExpression`
inputs, numeric coefficients are rewritten using the same rules while preserving the symbolic
structure of the expression's string form.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is unnecessarily verbose. It is not necessary or desirable for documentation to spell out the precise behaviour of an open-source function, especially for a non-public function (like this).

This is a private function and the docstring should convey the high-level intent in as few words as possible - the high-level intent here is that the function attempts to produce a representation of simple fractions of pi, if any contained floating-point values are sufficiently close.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jakelishman Hi there, I am a human(my linkdin profile link is in the bio), I have used Codex for solving the issue, and I am open to any kind of suggestions possible. Please let me know what kinds of suggestions you want me to make.

Comment on lines +44 to +45
output (str): Output style. Supported values are ``"text"`` (default), ``"latex"``,
``"mpl"``, and ``"qasm"``.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The "supported values" line can be removed if the function is instead type-annotated by Literal["text", "latext", "mpl", "qasm"].

def test_invalid_output_raises(self):
"""Test invalid output styles raise."""
with self.assertRaisesRegex(
QiskitError, "pi_check parameter output should be text, latex, mpl, or qasm."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's not necessary to include the entire output message in the regex - that makes it harder to expand the options in the future. It's better to include a snippet long enough to uniquely (and obviously for the test reader) identify the message, but small enough it is likely to resist sensible changes in the future.

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

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Document pi_check correctly

3 participants