Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent typehints for NLocal family #10479

Merged
merged 6 commits into from
Jul 26, 2023

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Jul 24, 2023

Summary

Fixes #10456 and generally use collections.abc over typing.

Details and comments

Also makes the docs more consistent by removing the first line of the __init__ doc and the TODO in the Examples section (tracked in #10480).

@Cryoris Cryoris requested a review from a team as a code owner July 24, 2023 08:01
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

@Cryoris Cryoris added this to the 0.25.0 milestone Jul 24, 2023
@Cryoris Cryoris added documentation Something is not clear or an error documentation Changelog: None Do not include in changelog type: qa Issues and PRs that relate to testing and code quality and removed documentation Something is not clear or an error documentation labels Jul 24, 2023
@@ -730,7 +715,7 @@ def parameter_bounds(self, bounds: list[tuple[float, float]]) -> None:

def add_layer(
self,
other: Union["NLocal", qiskit.circuit.Instruction, QuantumCircuit],
other: QuantumCircuit | qiskit.circuit.Instruction,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

QuantumCircuit includes "NLocal" therefore I removed the explicit mention

@coveralls
Copy link

coveralls commented Jul 24, 2023

Pull Request Test Coverage Report for Build 5670996800

  • 19 of 21 (90.48%) changed or added relevant lines in 5 files are covered.
  • 499 unchanged lines in 20 files lost coverage.
  • Overall coverage increased (+0.008%) to 85.934%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/circuit/library/n_local/efficient_su2.py 6 7 85.71%
qiskit/circuit/library/n_local/two_local.py 4 5 80.0%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
qiskit/transpiler/passes/routing/sabre_swap.py 1 96.86%
qiskit/transpiler/passes/scheduling/alap.py 1 96.72%
qiskit/transpiler/passes/scheduling/asap.py 1 96.92%
qiskit/transpiler/passes/scheduling/scheduling/alap.py 1 94.87%
qiskit/transpiler/passes/scheduling/scheduling/asap.py 1 95.24%
qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py 1 94.59%
crates/qasm2/src/lex.rs 3 91.14%
qiskit/pulse/library/waveform.py 3 93.75%
qiskit/circuit/init.py 5 84.38%
Totals Coverage Status
Change from base Build 5631006520: 0.008%
Covered Lines: 73056
Relevant Lines: 85014

💛 - Coveralls

Comment on lines -95 to +94
initial_state: Optional[Any] = None,
initial_state: QuantumCircuit | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

Did this change deliberately?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I thought I left a comment on that -- yes this is on purpose, we deprecated Any a few months ago (it's already gone in some NLocal circuits) but it seems we forgot it here 🙂 Any was mainly for backwards compatibility with old applications code so we don't need it anymore

Comment on lines -210 to +206
def _convert_to_block(self, layer: Any) -> QuantumCircuit:
def _convert_to_block(self, layer: typing.Any) -> QuantumCircuit:
Copy link
Member

Choose a reason for hiding this comment

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

Any means "don't type check this", whereas object is the base of all Python objects. The fact that this function takes either probably indicates that there's some usage of these objects that ought to be tightened up a bit, but it's not a big deal (and out of scope of this PR anyway).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this can probably be changed to Operation

Comment on lines 118 to 122
num_qubits: Optional[int] = None,
entanglement: Union[str, List[List[int]], Callable[[int], List[int]]] = "reverse_linear",
num_qubits: int | None = None,
entanglement: str | list[list[int]] | Callable[[int], list[int]] = "full",
Copy link
Member

Choose a reason for hiding this comment

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

This is a change in default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, that change was not on purpose 😄

Copy link
Member

Choose a reason for hiding this comment

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

yes, it's always better to do "reverse_linear" and not "full" since it provides the same unitary, but with O(n) CX gates instead of O(n^2)

jakelishman
jakelishman previously approved these changes Jul 24, 2023
@jakelishman jakelishman added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Jul 24, 2023
num_qubits: int | None = None,
rotation_blocks: str
| type
| qiskit.circuit.Instruction
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TwoLocal was missing Instruction as supported type

qiskit/circuit/library/n_local/efficient_su2.py Outdated Show resolved Hide resolved
qiskit/circuit/library/n_local/two_local.py Outdated Show resolved Hide resolved
qiskit/circuit/library/n_local/two_local.py Outdated Show resolved Hide resolved
Copy link
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.

Assuming this all passes now, then it's good to me.

@jakelishman jakelishman added this pull request to the merge queue Jul 26, 2023
Merged via the queue into Qiskit:main with commit eda570c Jul 26, 2023
13 checks passed
mergify bot pushed a commit that referenced this pull request Jul 26, 2023
* consistent typehints

* lint

* attempt to fix docs 1/?

* fix accidental default change

* fix lint

* fix , instead of |

(cherry picked from commit eda570c)
github-merge-queue bot pushed a commit that referenced this pull request Jul 26, 2023
* consistent typehints

* lint

* attempt to fix docs 1/?

* fix accidental default change

* fix lint

* fix , instead of |

(cherry picked from commit eda570c)

Co-authored-by: Julien Gacon <gaconju@gmail.com>
to24toro pushed a commit to to24toro/qiskit-terra that referenced this pull request Aug 3, 2023
* consistent typehints

* lint

* attempt to fix docs 1/?

* fix accidental default change

* fix lint

* fix , instead of |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog stable backport potential The bug might be minimal and/or import enough to be port to stable type: qa Issues and PRs that relate to testing and code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix flatten option type hint for consistency
6 participants