question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Instruction.params updates not reflected in definition (if definition already called)

See original GitHub issue

Information

  • Qiskit Terra version: master
  • Python version: 3.5
  • Operating system: osx 10.14

What is the current behavior?

.params values are fixed in gate definitions the first time ._define is called, and not updated, even if Instruction.params changes.

>>> from qiskit.extensions.standard import RZGate
>>> # Create a gate, and check the parameter values in its definition
...
>>> g = RZGate(0.1)
>>> g.definition
[(<qiskit.extensions.standard.u1.U1Gate object at 0x10b181208>, [Qubit(QuantumRegister(1, 'q'), 0)], [])]
>>> g.definition[0][0].params
[0.1]
>>> # Create a gate, change its parameters, then check parameter values in its definition
...
>>> g = RZGate(0.1)
>>> g.params[0] = 0.2
>>> g.definition[0][0].params
[0.2]
>>> # Create a gate, check its definition, updates its params, and see if the update is reflected in the definition
...
>>> g = RZGate(0.1)
>>> g.definition[0][0].params
[0.1]
>>> g.params[0] = 0.2
>>> g.definition[0][0].params
[0.1]

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Cryoriscommented, Dec 17, 2021

Personally, I’m not convinced params should be publically writeable at all. It might be both safer to users and easier for us to handle if gates define setters for mutable attributes. Parameterized gates, for instance, can be bound (or re-bound in future?) to certain values but covering the bind_parameters path and a direct access seems overcomplicated. ]

0reactions
jwoehrcommented, Dec 17, 2021

Still valid. Here’s a cleanup of the example:

from qiskit.circuit.library import RZGate
print('Create a gate, and check the parameter values in its definition')
g = RZGate(0.1)
print(g.definition)
print(g.definition[0][0].params)
print('Create a gate, change its parameters, then check parameter values in its definition')
g = RZGate(0.1)
g.params[0] = 0.2
print(g.definition[0][0].params)
print('Create a gate, check its definition, updates its params, and see if the update is reflected in the definition')
g = RZGate(0.1)
print(g.definition[0][0].params)
g.params[0] = 0.2
print(g.definition[0][0].params)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use parameters in queries, forms, and reports
This article explains how to use forms in Access to enhance your use of parameters in queries, forms, and reports.
Read more >
parameter was not defined" Inserting data - Stack Overflow
Just to provide an answer - because this error is pretty common - here are a few causes: The :parameter name does not...
Read more >
Parameters - Looker Studio Help - Google Help
Parameters let you interact with user-provided data. For example, you can create calculated fields that include input from people using your report, ...
Read more >
HTTP/1.1: Header Field Definitions
When such a directive appears with a 1#field-name parameter, it applies only to the named field or fields, and not to the rest...
Read more >
Manual Jobs - Ex Libris Knowledge Center
Name Content Type (set type) Type Delete Local Authority Records Authority MMS Withdraw Export Authority Records Authority MMS Export Add Bib to Collection Bibliographic title MARC21...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found