-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Allow ParameterExpression values in TemplateOptimization pass
#6899
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 all commits
Commits
Show all changes
142 commits
Select commit
Hold shift + click to select a range
32ee4db
added new equivalence rzx_zz4
nbronn 8cfc6d9
added another zz-ish template (looks for basis gates)
nbronn c063402
Merge branch 'master' of github.com:Qiskit/qiskit-terra into template…
nbronn 1d290a4
put the rzx_templates in
nbronn ad85838
looking at adding additions to rzx templates
nbronn 7098e4f
fixes parsing of Parameter name for sympy during template optimization
nbronn 3e23380
Merge branch 'main' of github.com:nbronn/qiskit-terra into template-p…
nbronn 6e18a54
Merge branch 'main' into template-param-expression
nbronn c7605d7
generalized fix for multiple parameters in an expression and constant…
nbronn ed74ccf
one more minor fix to bring inline with qiskit-terra main
nbronn e308b84
trying to fix parameter parsing for template optimization
nbronn 8fc1fa6
made sure floats were added correctly to (template) parameters
nbronn 78d3339
got template matching to work with floats, sympy still not understand…
nbronn cc1a55a
Merge branch 'main' of github.com:Qiskit/qiskit-terra into template-p…
nbronn 732e887
further modifications to accept circuit parameters for template optim…
nbronn 0c63ca2
debugging the binding of template parameters
nbronn 6a18dd1
realized I was not treating ParameterExpressions carefully and should…
nbronn 133171c
converted all bindings to ParameterExpressions (via .assign()), set t…
nbronn caee274
cleaned up _attempt_bind routine
nbronn bd67056
exploring overriding removing the matched scenarios with parameters
nbronn 38e8bde
introduced a total hack for dealing with ParamterExpressions that con…
nbronn a99726a
(non-latex) parameters now currently working in template optimization…
nbronn 59009db
cleaned up some whitespace and removed commented-out lines
nbronn 432bb3f
cleaned up some tox/lint errors
nbronn b308587
removed unneccessary Parameter import
nbronn 5fd736a
Merge branch 'main' into template-param-expression
nbronn 71aa17e
bypassed unit test test_unbound_parameters() and re-tox/lint
nbronn 5c3a62b
Merge branch 'main' of github.com:Qiskit/qiskit-terra into template-p…
nbronn 9f373e9
Merge branch 'template-param-expression' of github.com:nbronn/qiskit-…
nbronn bf590d3
fixed one last linting issue
nbronn 0f5f0d6
fixed cyclic import error
nbronn 4f5b69e
Merge branch 'main' into template-param-expression
nbronn bd3f9ed
modified calibration_creator to accept a ParameterExpression containi…
nbronn 6c9831c
Merge branch 'template-param-expression' of github.com:nbronn/qiskit-…
nbronn d9530e6
fixed an mismatch when trying to add calibrations and addressed a con…
nbronn 06b9cf1
Merge branch 'main' into template-param-expression
nbronn a9e7cdf
last tox/lint checks i'm sure ;)
nbronn 4ea8ff5
moved try/except from scheduling to calibration
nbronn 443a6c9
now params comes from node_op argument
nbronn 04dfc37
Merge branch 'main' of github.com:Qiskit/qiskit-terra into template-p…
nbronn 168c3cc
handling error in case gate parameters is empty in dagcircuit.py
nbronn 0e9c39f
Merge branch 'main' of github.com:Qiskit/qiskit-terra into template-p…
nbronn d7b55b3
Merge branch 'main' into template-param-expression
nbronn 0547f53
Merge branch 'main' into template-param-expression
nbronn fa51c3c
Fix template matching for parameters with LaTeX name.
rafal-pracht d4044a0
Merge pull request #1 from rafal-pracht/template-param-expression
nbronn 19007b7
Merge branch 'main' into template-param-expression
nbronn d6e1cd7
Merge branch 'main' into template-param-expression
nbronn 2065826
added missing docstring
nbronn a8b9b05
removed pdb set_trace
nbronn 72990f5
Merge branch 'main' into template-param-expression
nbronn d177d84
Merge branch 'main' into template-param-expression
nbronn bd6dda4
made changes requested in PR 6899
nbronn 6ea9d90
made changes requested in PR 6899 #2
nbronn 592963b
Merge branch 'main' into template-param-expression
nbronn cebce74
remembered to tighten try/except handling
nbronn 4e2291c
Merge branch 'template-param-expression' of github.com:nbronn/qiskit-…
nbronn 6ccf293
Merge branch 'main' into template-param-expression
nbronn 8b6bf37
finished making changes requested in PR 6899
nbronn fdffda6
Merge branch 'main' into template-param-expression
nbronn 7721f23
fixed remaining linting issue
nbronn 9130a2a
Merge branch 'main' into template-param-expression
nbronn 5e31398
added comment about templates working for parameterized RZXGates and …
nbronn eb8ba0d
Merge branch 'template-param-expression' of github.com:nbronn/qiskit-…
nbronn a92b942
Merge branch 'main' into template-param-expression
nbronn 84d65df
Merge branch 'main' into template-param-expression
nbronn 17d5002
Merge branch 'main' into template-param-expression
nbronn 3db29f0
Merge branch 'main' into template-param-expression
nbronn 31b3d62
Merge branch 'main' into template-param-expression
nbronn 1e8b009
Merge branch 'main' into template-param-expression
nbronn bdee233
Merge branch 'main' into template-param-expression
nbronn 6d419de
Merge branch 'main' into template-param-expression
nbronn b362089
Merge branch 'main' into template-param-expression
nbronn 2973339
Fix test unbound parameters
rafal-pracht bb1c797
Check if matrix with Parameter is unitary
rafal-pracht d531d95
Merge branch 'template-param-expression' into template-param-expression
rafal-pracht 30706cd
Merge branch 'main' of github.com:Qiskit/qiskit-terra into template-p…
nbronn 9260cf4
Fix merge issue
rafal-pracht 767ccf4
Merge pull request #4 from rafal-pracht/template-param-expression
nbronn 28b384f
Merge branch 'main' into template-param-expression
nbronn d55e75c
Merge branch 'template-param-expression' of github.com:nbronn/qiskit-…
nbronn f50c4e6
removed real=True in two symbol Symbol expressions, which was messing…
nbronn e32d038
generalized to iterate over parameters, and removed reference to priv…
nbronn c21fdf1
modified .get_sympy_expr() to use symengine if possible
nbronn bc42afb
made the negation of the RXGate() much less verbose
nbronn cce7b65
working thru tox/lint checks
nbronn 5506200
added unit test test_unbound_parameters_in_rzx_templates to confirm t…
nbronn 708bfcc
Fix unbund parameters test
rafal-pracht 84d566b
Merge pull request #6 from rafal-pracht/template-param-expression
nbronn 54403b0
fixed issue with adding calibrations without params
nbronn 3c15da0
Merge branch 'main' into template-param-expression
nbronn 9355893
Add real=True to symbols
rafal-pracht 7e9f8d9
fixed linting issue
nbronn 0a179b6
Fix for symengine
rafal-pracht 5f86049
simplified the parameter handling for adding calibrations to gates
nbronn 0835763
Merge pull request #7 from rafal-pracht/template-param-expression
nbronn 680ec53
added a check for unitary on an arbitrary float in the case symengine…
nbronn f276cd7
Parammeter can be complex
rafal-pracht a295831
Merge pull request #8 from rafal-pracht/template-param-expression
nbronn 2f244bc
Merge branch 'main' into template-param-expression
nbronn 0434a70
Merge branch 'template-param-expression' of github.com:nbronn/qiskit-…
nbronn 055832d
fixed tox/lint issues
nbronn 2504c2e
removed one more imposition of real parameters
nbronn 0f1cf5d
one last linting issue
nbronn c672ee3
Merge branch 'main' into template-param-expression
nbronn 9a94bb2
modified release notes
nbronn 48173c1
fixed some transpiler library imports that were out of date
nbronn 24097b5
added sphinx referencing to release notes and print statement for the…
nbronn 2f0203c
fixed some tox/lint issues
nbronn 591763a
Fix review issues
rafal-pracht 4dcf014
Merge branch 'main' into template-param-expression
nbronn 8d1bc2e
Merge pull request #10 from rafal-pracht/template-param-expression
nbronn 4f76b73
Merge branch 'template-param-expression' of github.com:nbronn/qiskit-…
nbronn c8a08e9
fixing last tox/lint issues
nbronn ee081e3
looking into tox/lint issues
nbronn 3f740fb
added release notes and fixed tox/lint issues
nbronn 69b8472
added method in template_substitution to compare the number of parame…
nbronn 58c8ccf
Merge branch 'main' of github.com:Qiskit/qiskit-terra into template-p…
nbronn e09b1e3
fixing up some template matching unit tests
nbronn f01a671
fixed up template matching unit tests to remove calls to UnitaryGate
nbronn 78a2f47
Update qiskit/dagcircuit/dagcircuit.py
nbronn 8496a8c
Update qiskit/extensions/unitary.py
nbronn 82470fd
Update qiskit/extensions/unitary.py
nbronn 1f17aff
added template test with two parameters and new logic in the case the…
nbronn fb8ca5c
added two-parameter unit test and a check for overlapping parameters …
nbronn 0ce2fa1
Merge branch 'main' of github.com:Qiskit/qiskit-terra into template-p…
nbronn 9f59e06
Merge branch 'template-param-expression' of github.com:nbronn/qiskit-…
nbronn 5de0384
remove ParameterTypeeException from exceptions.py
nbronn 7906036
Restore lazy symengine imports
jakelishman 092f92b
Rename to_sympify_expression to sympify
jakelishman 95dbcfb
Revert now-unnecessary changes to calibration builder
jakelishman 908f87d
Fixup release note
jakelishman fc83156
Add explicit tests of template matching pass
jakelishman a14dc37
Fix template parameter substitution
jakelishman 9d07849
Merge remote-tracking branch 'ibm/main' into template-param-expression
jakelishman 7034789
Fix overlooked documentation comment
jakelishman 16bbffb
Remove qasm.pi import in favour of numpy
jakelishman 317e2a6
Add tests of multi-parameter instructions
jakelishman 6ccc663
Fix template matching with multiparameter expressions
jakelishman 94e1884
Silence overzealous pylint warning
jakelishman 87e5fe8
Merge remote-tracking branch 'ibm/main' into template-param-expression
jakelishman df9c3d3
Merge branch 'main' into template-param-expression
mergify[bot] 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
74 changes: 74 additions & 0 deletions
74
releasenotes/notes/add-parameters-to-template-substitution-a1379cdbfcc10b5c.yaml
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,74 @@ | ||
| --- | ||
| features: | ||
| - | | ||
| The :class:`.ParameterExpression` class is now allowed in the | ||
| template optimization transpiler pass. An illustrative example | ||
| of using :class:`.Parameter`\s is the following: | ||
|
|
||
| .. code-block:: | ||
|
|
||
| from qiskit import QuantumCircuit, transpile, schedule | ||
| from qiskit.circuit import Parameter | ||
|
|
||
| from qiskit.transpiler import PassManager | ||
| from qiskit.transpiler.passes import TemplateOptimization | ||
|
|
||
| # New contributions to the template optimization | ||
| from qiskit.transpiler.passes.calibration import RZXCalibrationBuilder, rzx_templates | ||
|
|
||
| from qiskit.test.mock import FakeCasablanca | ||
| backend = FakeCasablanca() | ||
|
|
||
| phi = Parameter('φ') | ||
|
|
||
| qc = QuantumCircuit(2) | ||
| qc.cx(0,1) | ||
| qc.p(2*phi, 1) | ||
| qc.cx(0,1) | ||
| print('Original circuit:') | ||
| print(qc) | ||
|
|
||
| pass_ = TemplateOptimization(**rzx_templates.rzx_templates(['zz2'])) | ||
| qc_cz = PassManager(pass_).run(qc) | ||
| print('ZX based circuit:') | ||
| print(qc_cz) | ||
|
|
||
| # Add the calibrations | ||
| pass_ = RZXCalibrationBuilder(backend) | ||
| cal_qc = PassManager(pass_).run(qc_cz.bind_parameters({phi: 0.12})) | ||
|
|
||
| # Transpile to the backend basis gates | ||
| cal_qct = transpile(cal_qc, backend) | ||
| qct = transpile(qc.bind_parameters({phi: 0.12}), backend) | ||
|
|
||
| # Compare the schedule durations | ||
| print('Duration of schedule with the calibration:') | ||
| print(schedule(cal_qct, backend).duration) | ||
| print('Duration of standard with two CNOT gates:') | ||
| print(schedule(qct, backend).duration) | ||
|
|
||
| outputs | ||
|
|
||
| .. parsed-literal:: | ||
|
|
||
| Original circuit: | ||
|
|
||
| q_0: ──■──────────────■── | ||
| ┌─┴─┐┌────────┐┌─┴─┐ | ||
| q_1: ┤ X ├┤ P(2*φ) ├┤ X ├ | ||
| └───┘└────────┘└───┘ | ||
| ZX based circuit: | ||
| ┌─────────────┐ » | ||
| q_0: ────────────────────────────────────┤0 ├────────────» | ||
| ┌──────────┐┌──────────┐┌──────────┐│ Rzx(2.0*φ) │┌──────────┐» | ||
| q_1: ┤ Rz(-π/2) ├┤ Rx(-π/2) ├┤ Rz(-π/2) ├┤1 ├┤ Rx(-2*φ) ├» | ||
| └──────────┘└──────────┘└──────────┘└─────────────┘└──────────┘» | ||
| « | ||
| «q_0: ──────────────────────────────────────────────── | ||
| « ┌──────────┐┌──────────┐┌──────────┐┌──────────┐ | ||
| «q_1: ┤ Rz(-π/2) ├┤ Rx(-π/2) ├┤ Rz(-π/2) ├┤ P(2.0*φ) ├ | ||
| « └──────────┘└──────────┘└──────────┘└──────────┘ | ||
| Duration of schedule with the calibration: | ||
| 1600 | ||
| Duration of standard with two CNOT gates: | ||
| 6848 |
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.