-
Notifications
You must be signed in to change notification settings - Fork 708
Port subroutine resource templates to estimator #8300
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
Merged
Merged
Changes from 250 commits
Commits
Show all changes
635 commits
Select commit
Hold shift + click to select a range
a6fef0c
remove tests
soranjh f2d5ce7
add symbolic
soranjh d7bfeeb
fix conflict
soranjh b8fd88e
update init
soranjh 4fe179e
Updated adjoint class
ddhawan11 8da4b95
Merge branch 'master' into add-single-paramteric-ops
ddhawan11 3f936d0
update arg name
soranjh 050452a
Updated typechecks for nonparametric
ddhawan11 a1a364a
Merge remote-tracking branch 'origin/add-single-paramteric-ops' into …
ddhawan11 f08c485
Merge branch 'add-controlled-ops' into add-control-adjoint-symbolic
ddhawan11 b18e188
Update pennylane/estimator/ops/qubit/parametric_ops_single_qubit.py
ddhawan11 6a304e4
update arg name
soranjh 9472959
Fixed tesst
ddhawan11 0cb6524
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 187bfe5
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 5dfc807
Added typechecks
ddhawan11 a973e74
Increased test coverage
ddhawan11 f42426d
Update tests/estimator/test_estimator_resOp.py
ddhawan11 4423f43
Fixed tests and signature
ddhawan11 7b23eb0
Fixed documentation
ddhawan11 87be3ed
Fix docs
ddhawan11 d7d99f2
Fix docs
ddhawan11 ba954a3
minor doc fix
ddhawan11 64a6061
minor doc fix
ddhawan11 18d9afc
fixed docs build
ddhawan11 a6a5cc2
fixed rendering
ddhawan11 ec5c2eb
Merge branch 'add-control-adjoint-symbolic' into add-multi-qubit-para…
ddhawan11 fa248c9
Fixed examples
ddhawan11 57dd102
Update pennylane/estimator/__init__.py
ddhawan11 165eef0
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 06632de
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 deb807d
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 bb4474a
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 1ee832c
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 42174e5
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 ccc8fb6
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 79864bf
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 a6fcd3b
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 fff05fa
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 1d1ba68
minor doc change
ddhawan11 f3edf4d
clean->zero
ddhawan11 dda1192
fix doc build
ddhawan11 2738fb6
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 0173012
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 34153cf
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 f59a290
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 af1a877
Renamed TempAND
ddhawan11 f7164e3
Updated changelog
ddhawan11 0c8efc9
Merge branch 'add-controlled-ops' into add-control-adjoint-symbolic
ddhawan11 0dd6777
fixed tests
ddhawan11 33b8a51
updated changelog
ddhawan11 fcaf87f
Merge branch 'add-control-adjoint-symbolic' into add-multi-qubit-para…
ddhawan11 fc0393d
move files
soranjh 37c77bd
update names
soranjh b452eb9
move files
soranjh d8c641f
rename ops
soranjh 584c32b
update tests
soranjh 250108c
Update tests/estimator/ops/test_estimator_symbolics.py
ddhawan11 1508695
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 7f39f2a
update names
soranjh 770e7e2
fix tests
soranjh a1bee15
fix more tests
soranjh 2520912
fix all tests
soranjh b1ee21c
Added validation checks
ddhawan11 d9bb0ae
Added validation
ddhawan11 aa6bcb9
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 7ccf052
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 253e156
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 a43adaf
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 44bedcb
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 d60c2e0
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 76d3f55
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 38f3fac
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 63658e5
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 b7d72a0
Update pennylane/estimator/ops/op_math/controlled_ops.py
ddhawan11 ea9f392
Update pennylane/estimator/ops/identity.py
ddhawan11 5fdc13a
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 c278970
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 1edd79a
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 deeff3c
Update pennylane/estimator/ops/qubit/non_parametric_ops.py
ddhawan11 947a9f2
Update pennylane/estimator/ops/qubit/non_parametric_ops.py
ddhawan11 e9f42b2
add guard clause
soranjh 5ccafd9
add type hint
soranjh a1fc4ba
update examples
soranjh b9468c0
Merge branch 'add-multi-qubit-parametric' into add-subroutines-to-est…
soranjh ec84532
update name
soranjh bfc915b
Merge branch 'add-controlled-ops' into add-control-adjoint-symbolic
ddhawan11 b4729c3
Merge branch 'add-control-adjoint-symbolic' into add-multi-qubit-para…
ddhawan11 d04f9d2
run black on init
soranjh 6644834
add fix for pylint
soranjh 43e17cc
add fix for pylint
soranjh 1531ee5
correct import
soranjh c0313b9
correct format
soranjh 339abe1
fix type hint
soranjh cb866c1
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 4fb27f7
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 1a1a057
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 503681e
update signature
soranjh d1b08cc
update wire names
soranjh 8adab4c
update doc
soranjh 27993d3
fix pylint
soranjh 4fc7549
Addressed comment
ddhawan11 3dad56c
fix doc links
soranjh af2ec38
fix pylint
soranjh b5b4d06
fix doc
soranjh 7e20816
[skip ci] fix doc
soranjh 471a730
Merge branch 'master' into add-controlled-ops
ddhawan11 aa67d96
fixed unwanted changes
ddhawan11 8b7f4b2
fix doc links
soranjh f68bf6d
Resolved conflicts
ddhawan11 4cad155
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 35dc4f8
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 ce03cd7
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 7a43383
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 b5b8f22
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 4c1ad60
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 0d80499
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 6be8c88
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 df9dbaf
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 ba3cfbd
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 88b6eab
Merge remote-tracking branch 'origin/add-control-adjoint-symbolic' in…
ddhawan11 bff5072
fix links
soranjh 8a453f4
Addressed comments
ddhawan11 ab60a03
Added mcx for cnot controlled
ddhawan11 d592227
formatting
ddhawan11 95705ae
updated changelog
ddhawan11 2a45ec0
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 b8094f0
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 f899b4d
Update pennylane/estimator/ops/qubit/non_parametric_ops.py
ddhawan11 997a466
Update pennylane/estimator/ops/qubit/non_parametric_ops.py
ddhawan11 b2cd480
Update pennylane/estimator/ops/qubit/non_parametric_ops.py
ddhawan11 bbb59c7
Update pennylane/estimator/ops/qubit/non_parametric_ops.py
ddhawan11 021b877
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 304b136
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 6b55cd0
rearrange files
soranjh 6077d49
fixed docs
ddhawan11 0215800
Merge branch 'add-multi-qubit-parametric' into add-subroutines-to-est…
soranjh f4d8c9a
fix sphinx
ddhawan11 c46f7e8
Merge branch 'master' into add-controlled-ops
ddhawan11 53278df
Merge branch 'add-controlled-ops' into add-control-adjoint-symbolic
ddhawan11 3c77db6
Addressed comments
ddhawan11 3c3502e
Merge branch 'add-control-adjoint-symbolic' into add-multi-qubit-para…
ddhawan11 19a1e04
fixed formatting
ddhawan11 ceaabe8
sphnx fix
ddhawan11 05805b1
sphinx fix
ddhawan11 1f7d356
update rst
soranjh 63a53c4
fix link
soranjh c5cfb47
Merge branch 'add-multi-qubit-parametric' into add-subroutines-to-est…
soranjh e826cdf
check
ddhawan11 8b717dd
Merge branch 'master' into add-controlled-ops
ddhawan11 77190d2
sphinx fix
ddhawan11 065de4f
Merge branch 'master' into add-controlled-ops
ddhawan11 3b13bde
check
ddhawan11 ab85f0f
fix links
ddhawan11 ad164ee
fix sphinx check
ddhawan11 c89e7a1
Merge branch 'master' into add-controlled-ops
ddhawan11 9f3026c
fix rendering
ddhawan11 5140386
Merge branch 'add-controlled-ops' into add-control-adjoint-symbolic
ddhawan11 6dd5c44
Update tests/estimator/ops/test_estimator_identity.py
ddhawan11 9021452
Merge branch 'add-control-adjoint-symbolic' into add-multi-qubit-para…
ddhawan11 679f8da
remove unused import
soranjh 2127d69
update docstring
soranjh 5f01ad2
Merge branch 'add-control-adjoint-symbolic' into add-multi-qubit-para…
soranjh 566e238
correct format
soranjh eb9b172
run isort
soranjh 1ab39ce
Merge branch 'add-control-adjoint-symbolic' into add-multi-qubit-para…
soranjh e3358e9
fix test
soranjh 98794e8
update format
soranjh 8032098
Merge branch 'add-multi-qubit-parametric' into add-subroutines-to-est…
soranjh e6680ff
fix indentation
soranjh 066163c
fix format
soranjh e8f2b07
correct format
soranjh 7f3e848
Merge branch 'add-multi-qubit-parametric' into add-subroutines-to-est…
soranjh f32ed66
run isort
soranjh 5290a02
add error test
soranjh 50c8465
Merge branch 'master' into add-control-adjoint-symbolic
ddhawan11 589cb8e
Merge branch 'add-control-adjoint-symbolic' into add-multi-qubit-para…
ddhawan11 b5f4dbb
expand test
soranjh 7f99386
formatting
ddhawan11 a9c3618
formatting
ddhawan11 7987748
merge master and fix conflicts
soranjh d30a469
add extra test
soranjh cc84168
increased test coverage
ddhawan11 fa4675d
Update doc/releases/changelog-dev.md
ddhawan11 55da199
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 9ecdc65
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 082aa39
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 f5233d5
Addressed comments
ddhawan11 06fbb6a
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 6cbd783
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 16608e6
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 3c151b8
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 43eecfc
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 c0552a2
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 831d14c
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 e319543
Update pennylane/estimator/ops/qubit/qchem_ops.py
ddhawan11 b969188
Update pennylane/estimator/ops/qubit/qchem_ops.py
ddhawan11 d44a976
Added example
ddhawan11 67bab4a
add missing tests
soranjh 9df7e74
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 8858cca
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 8045644
add test
soranjh 9dc9a55
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 b12586d
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 d3621f4
Update pennylane/estimator/ops/op_math/symbolic.py
ddhawan11 49ef3a4
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 92af8e8
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 5d307cf
Update pennylane/estimator/ops/qubit/parametric_ops_multi_qubit.py
ddhawan11 7fd03c2
Update doc/code/qml_estimator.rst
ddhawan11 57b6317
add more tests
soranjh 56985d0
Merge branch 'add-multi-qubit-parametric' into add-subroutines-to-est…
soranjh 3059223
check
ddhawan11 d562897
fix docs
ddhawan11 3105ced
Merge branch 'add-multi-qubit-parametric' into add-subroutines-to-est…
soranjh 41ca4ed
merge master and fix conflict
soranjh b8c1ed2
Apply suggestions from code review
soranjh cab51ee
update changelog
soranjh 1ccf6a0
move qubitunitary to new module
soranjh f3c86ec
change names
soranjh 9ece755
update names
soranjh 00079ef
fix tests
soranjh 6e72018
add usage details to qft
soranjh 450057b
update rst
soranjh 125183f
Merge branch 'master' into add-subroutines-to-estimator
soranjh ad0aa2f
Apply suggestions from code review
soranjh 9633205
update rst
soranjh 6efa283
fix docs
soranjh 664844c
create templates folder
soranjh 72c6cb5
correct link
soranjh ebd5e4c
update rst
soranjh 0affc39
use original conf
soranjh 0d25d04
import paths
austingmhuang 9726792
merg confs
austingmhuang e8dea30
update conf to include templates
soranjh 8948c45
Merge branch 'master' into add-subroutines-to-estimator
soranjh d105f74
Merge branch 'add-subroutines-to-estimator' of https://github.com/Pen…
soranjh 2215c2b
remove trotter
soranjh b331537
fix qft format
soranjh eac658b
fix config link
soranjh bb5b3ef
apply review comments
soranjh d39579e
update rst
soranjh 65de59e
change zeroed to restored in qrom
soranjh b7fa888
Merge branch 'master' into add-subroutines-to-estimator
soranjh 1aeacf3
update changelog
soranjh c935b1f
correct phase shift
soranjh 19b245e
update format
soranjh 0a4de3e
Merge branch 'master' into add-subroutines-to-estimator
soranjh 986f35b
Merge branch 'master' into add-subroutines-to-estimator
soranjh 8d7f15b
Merge branch 'master' into add-subroutines-to-estimator
soranjh e9fb1f3
Merge branch 'master' into add-subroutines-to-estimator
soranjh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| PauliRot, | ||
| MultiRZ, | ||
| SingleExcitation, | ||
| QubitUnitary, | ||
| ) | ||
|
|
||
| from .op_math import ( | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| # Copyright 2025 Xanadu Quantum Technologies Inc. | ||
|
|
||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
|
|
||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| r"""Resource operators for QubitUnitary operation.""" | ||
| import pennylane.estimator as qre | ||
| from pennylane.estimator.resource_operator import ( | ||
| CompressedResourceOp, | ||
| GateCount, | ||
| ResourceOperator, | ||
| resource_rep, | ||
| ) | ||
| from pennylane.estimator.templates import SelectPauliRot | ||
| from pennylane.wires import WiresLike | ||
|
|
||
| # pylint: disable=arguments-differ | ||
|
|
||
|
|
||
| class QubitUnitary(ResourceOperator): | ||
| r"""Resource class for the QubitUnitary template. | ||
| Args: | ||
| num_wires (int): the number of qubits the operation acts upon | ||
| precision (Union[float, None], optional): The precision used when preparing the single qubit | ||
| rotations used to synthesize the n-qubit unitary. | ||
| wires (Sequence[int], None): the wires the operation acts on | ||
| Resources: | ||
| The resources are defined by combining the two equalities in `Möttönen and Vartiainen | ||
| (2005), Fig 14 <https://arxiv.org/pdf/quant-ph/0504100>`_ , we can express an :math:`n` | ||
| qubit unitary as four :math:`n - 1` qubit unitaries and three multiplexed rotations | ||
| via (:class:`~.pennylane.estimator.templates.subroutines.SelectPauliRot`). Specifically, the cost | ||
| is given by: | ||
| * 1-qubit unitary, the cost is approximated as a single :code:`RZ` rotation. | ||
| * 2-qubit unitary, the cost is approximated as four single qubit rotations and three :code:`CNOT` gates. | ||
| * 3-qubit unitary or more, the cost is given according to the reference above, recursively. | ||
| .. seealso:: The associated PennyLane operation :class:`~.pennylane.QubitUnitary`. | ||
| **Example** | ||
| The resources for this operation are computed using: | ||
| >>> import pennylane.estimator as qre | ||
| >>> qu = qre.QubitUnitary(num_wires=3) | ||
| >>> print(qre.estimate(qu, gate_set)) | ||
| --- Resources: --- | ||
| Total qubits: 3 | ||
| Total gates : 52 | ||
| Qubit breakdown: | ||
| zeroed qubits: 0, any_state qubits: 0, algorithmic qubits: 3 | ||
| Gate breakdown: | ||
| {'RZ': 24, 'CNOT': 24, 'RY': 4} | ||
| """ | ||
|
|
||
| resource_keys = {"num_wires", "precision"} | ||
|
|
||
| def __init__(self, num_wires: int, precision: float | None = None, wires: WiresLike = None): | ||
| self.num_wires = num_wires | ||
| self.precision = precision | ||
| super().__init__(wires=wires) | ||
|
|
||
| @property | ||
| def resource_params(self) -> dict: | ||
| r"""Returns a dictionary containing the minimal information needed to compute the resources. | ||
| Returns: | ||
| dict: A dictionary containing the resource parameters: | ||
| * num_wires (int): the number of qubits the operation acts upon | ||
| * precision (Union[float, None], optional): The precision used when preparing the | ||
| single qubit rotations used to synthesize the n-qubit unitary. | ||
| """ | ||
| return {"num_wires": self.num_wires, "precision": self.precision} | ||
|
|
||
| @classmethod | ||
| def resource_rep(cls, num_wires, precision=None) -> CompressedResourceOp: | ||
| r"""Returns a compressed representation containing only the parameters of | ||
| the Operator that are needed to compute the resources. | ||
| Args: | ||
| num_wires (int): the number of qubits the operation acts upon | ||
| precision (Union[float, None], optional): The precision used when preparing the single | ||
| qubit rotations used to synthesize the n-qubit unitary. | ||
| Returns: | ||
| :class:`~.pennylane.estimator.resource_operator.CompressedResourceOp`: the operator in a compressed representation | ||
| """ | ||
| params = {"num_wires": num_wires, "precision": precision} | ||
| return CompressedResourceOp(cls, num_wires, params) | ||
|
|
||
| @classmethod | ||
| def resource_decomp(cls, num_wires, precision=None) -> list[GateCount]: | ||
| r"""Returns a list representing the resources of the operator. Each object in the list | ||
| represents a gate and the number of times it occurs in the circuit. | ||
| Args: | ||
| num_wires (int): the number of qubits the operation acts upon | ||
| precision (Union[float, None], optional): The precision used when preparing the single | ||
soranjh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| qubit rotations used to synthesize the n-qubit unitary. | ||
| Resources: | ||
| The resources are defined by combining the two equalities in `Möttönen and Vartiainen | ||
| (2005), Fig 14 <https://arxiv.org/pdf/quant-ph/0504100>`_, we can express an :math:`n`- | ||
| qubit unitary as four :math:`n - 1`-qubit unitaries and three multiplexed rotations | ||
| via (:class:`~.pennylane.estimator.templates.subroutines.SelectPauliRot`). Specifically, the cost | ||
| is given by: | ||
| * 1-qubit unitary, the cost is approximated as a single :code:`RZ` rotation. | ||
| * 2-qubit unitary, the cost is approximated as four single qubit rotations and three :code:`CNOT` gates. | ||
| * 3-qubit unitary or more, the cost is given according to the reference above, recursively. | ||
| Returns: | ||
| list[:class:`~.pennylane.estimator.resource_operator.GateCount`]: A list of GateCount objects, where each object | ||
| represents a specific quantum gate and the number of times it appears | ||
| in the decomposition. | ||
| """ | ||
| gate_lst = [] | ||
|
|
||
| one_qubit_decomp_cost = [GateCount(resource_rep(qre.RZ, {"precision": precision}))] | ||
| two_qubit_decomp_cost = [ | ||
| GateCount(resource_rep(qre.RZ, {"precision": precision}), 4), | ||
| GateCount(resource_rep(qre.CNOT), 3), | ||
| ] | ||
|
|
||
| if num_wires == 1: | ||
| return one_qubit_decomp_cost | ||
|
|
||
| if num_wires == 2: | ||
| return two_qubit_decomp_cost | ||
|
|
||
| for gc in two_qubit_decomp_cost: | ||
| gate_lst.append(4 ** (num_wires - 2) * gc) | ||
|
|
||
| for index in range(2, num_wires): | ||
| multiplex_z = resource_rep( | ||
| SelectPauliRot, | ||
| { | ||
| "num_ctrl_wires": index, | ||
| "rot_axis": "Z", | ||
| "precision": precision, | ||
| }, | ||
| ) | ||
| multiplex_y = resource_rep( | ||
| SelectPauliRot, | ||
| { | ||
| "num_ctrl_wires": index, | ||
| "rot_axis": "Y", | ||
| "precision": precision, | ||
| }, | ||
| ) | ||
|
|
||
| gate_lst.append(GateCount(multiplex_z, 2 * 4 ** (num_wires - (1 + index)))) | ||
| gate_lst.append(GateCount(multiplex_y, 4 ** (num_wires - (1 + index)))) | ||
|
|
||
| return gate_lst | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Copyright 2025 Xanadu Quantum Technologies Inc. | ||
|
|
||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
|
|
||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| r"""This module contains resource templates.""" | ||
|
|
||
| from .subroutines import ( | ||
| OutOfPlaceSquare, | ||
| PhaseGradient, | ||
| OutMultiplier, | ||
| SemiAdder, | ||
| QFT, | ||
| AQFT, | ||
| BasisRotation, | ||
| Select, | ||
| QROM, | ||
| SelectPauliRot, | ||
| ControlledSequence, | ||
| QPE, | ||
| IterativeQPE, | ||
| ) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.