Skip to content

Update circuit.delay to accept parameterized duration (Fix #6029)#6225

Merged
mergify[bot] merged 9 commits intoQiskit:mainfrom
itoko:fix-issue-6029-parameterized-delay
Apr 24, 2021
Merged

Update circuit.delay to accept parameterized duration (Fix #6029)#6225
mergify[bot] merged 9 commits intoQiskit:mainfrom
itoko:fix-issue-6029-parameterized-delay

Conversation

@itoko
Copy link
Copy Markdown
Contributor

@itoko itoko commented Apr 14, 2021

Summary

Updates circuit.Delayto be able to accept a parameterized duration as well as a fixed (integer/float) duration.
Fixes #6029.

Details and comments

Now you can specify a duration of delay as a ParameterExpression object when appending it to a circuit, and assign some value to the parameter afterward.

idle_dur = Parameter('t')
qc = QuantumCircuit(1, 1)
qc.x(0)
qc.delay(idle_dur, 0, 'us')
qc.measure(0, 0)
print(qc)  # parameterized delay in us (micro seconds)

# assign before transpilation
assigned = qc.assign_parameters({idle_dur: 0.1})
print(assigned)  # delay in us
transpiled = transpile(assigned, some_backend_with_dt)
print(transpiled)  # delay in dt

# assign after transpilation
transpiled = transpile(qc, some_backend_with_dt)
print(transpiled)  # parameterized delay in dt
assigned = transpiled.assign_parameters({idle_dur: 0.1})  # parameter's unit is kept in us
print(assigned)  # delay in dt

@itoko itoko requested a review from a team as a code owner April 14, 2021 00:35
@itoko itoko added the Changelog: Changed Add a "Changed" entry in the GitHub Release changelog. label Apr 14, 2021
@itoko itoko changed the title Update circuit.delay to accept parameterized duration delay (Fix #6029) Update circuit.delay to accept parameterized duration (Fix #6029) Apr 14, 2021
@itoko itoko added Changelog: Changed Add a "Changed" entry in the GitHub Release changelog. and removed Changelog: Changed Add a "Changed" entry in the GitHub Release changelog. labels Apr 14, 2021
@itoko itoko added this to the 0.18 milestone Apr 15, 2021
Copy link
Copy Markdown
Member

@kdk kdk left a comment

Choose a reason for hiding this comment

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

Thanks @itoko , this looks great.

@kdk kdk added the automerge label Apr 23, 2021
@mergify mergify Bot merged commit 5ae0613 into Qiskit:main Apr 24, 2021
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request May 5, 2021
The definition of the Delay's validate_parameter method was changed in
PR Qiskit#6225, this just updates it to use the new
ParameterExpression.is_real() so it works in a world with symengine.
mergify Bot pushed a commit that referenced this pull request May 5, 2021
* Use symengine for parameter and parameter expressions

This commit uses symengine by default everywhere sympy was previously
used. Symengine is a symbolic engine written in C++ that offers
significantly improved performance over sympy. However, because there
isn't 32 bit wheels available on pypi we can't have it as a hard
requirement in all environments. This adds it as a requirement on
supported platforms 64bit intel, arm64/aarch64, and ppc64le so by
default we have the better performance where available and in the code
there is a fallback to use sympy if it's not available.

* Add pickle support

* Pickle fixes

* Convert to sympy expression for eq and str

* Fix lint

* Fix vector pickle

* Avoid runtime import for symengine

Local benchmarking shows that importing symengine is not nearly as slow
as importing sympy. So to avoid the runtime overhead and reduce the
complexity this commit switches to use module level imports for
symengine.

* Fix test failures due to precision differences

* More fixes from subtle behavior differences

* Fix some of the gradient failures

* Fix failure in sympy fallback path

* Fix gradient tests

* Adjust complex check logic

* Fix lint

* Workaround pulse failure

* Adjust failing test to use np allclose

* Add release note

* Add is_real method to parameterexpression

* Run black post-rebase

* Remove symengine/sympy usage from gradients tests

* Remove unused import

* Fix Delay instruction's new validate is_real check

The definition of the Delay's validate_parameter method was changed in
PR #6225, this just updates it to use the new
ParameterExpression.is_real() so it works in a world with symengine.
@itoko itoko deleted the fix-issue-6029-parameterized-delay branch July 8, 2021 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Changed Add a "Changed" entry in the GitHub Release changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using parameters in delay gate

2 participants