diff --git a/qiskit/pulse/channels.py b/qiskit/pulse/channels.py index fb5971fb7a25..894d3737c4c1 100644 --- a/qiskit/pulse/channels.py +++ b/qiskit/pulse/channels.py @@ -102,10 +102,11 @@ def _validate_index(self, index: Any) -> None: raise PulseError('Channel index must be a nonnegative integer') @property - @deprecated_functionality def parameters(self) -> Set: """Parameters which determine the channel index.""" - return self._parameters + if isinstance(self.index, ParameterExpression): + return self.index.parameters + return set() def is_parameterized(self) -> bool: """Return True iff the channel is parameterized.""" diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index 4b916c6803af..f80d85ed9985 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -230,10 +230,14 @@ def append(self, schedule, return self.insert(time, schedule, name=name) @property - @deprecated_functionality def parameters(self) -> Set: """Parameters which determine the instruction behavior.""" - return set(self._parameter_table.keys()) + parameters = set() + for op in self.operands: + if hasattr(op, 'parameters'): + for op_param in op.parameters: + parameters.add(op_param) + return parameters def is_parameterized(self) -> bool: """Return True iff the instruction is parameterized.""" diff --git a/qiskit/pulse/instructions/play.py b/qiskit/pulse/instructions/play.py index 4697a90c4082..fd11780925bb 100644 --- a/qiskit/pulse/instructions/play.py +++ b/qiskit/pulse/instructions/play.py @@ -13,7 +13,7 @@ """An instruction to transmit a given pulse on a ``PulseChannel`` (i.e., those which support transmitted pulses, such as ``DriveChannel``). """ -from typing import Dict, Optional, Union, Tuple, Any +from typing import Dict, Optional, Union, Tuple, Any, Set from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType from qiskit.pulse.channels import PulseChannel @@ -93,6 +93,20 @@ def _initialize_parameter_table(self, # Table maps parameter to operand index, 0 for ``pulse`` self._parameter_table[param].append(0) + @property + def parameters(self) -> Set: + """Parameters which determine the instruction behavior.""" + parameters = set() + for pulse_param_expr in self.pulse.parameters.values(): + if isinstance(pulse_param_expr, ParameterExpression): + for pulse_param in pulse_param_expr.parameters: + parameters.add(pulse_param) + if self.channel.is_parameterized(): + for ch_param in self.channel.parameters: + parameters.add(ch_param) + + return parameters + @deprecated_functionality def assign_parameters(self, value_dict: Dict[ParameterExpression, ParameterValueType] diff --git a/releasenotes/notes/remove-parameter-deprecation-2568271bf2d19911.yaml b/releasenotes/notes/remove-parameter-deprecation-2568271bf2d19911.yaml new file mode 100644 index 000000000000..c49622e2e65f --- /dev/null +++ b/releasenotes/notes/remove-parameter-deprecation-2568271bf2d19911.yaml @@ -0,0 +1,5 @@ +--- +other: + - | + Deprecation warning for :meth:`~qiskit.pulse.Instruction.parameters` is dropped. + This method will continue to be supported. diff --git a/test/python/pulse/test_parameters.py b/test/python/pulse/test_parameters.py index f222dc2a3612..8a88357e553f 100644 --- a/test/python/pulse/test_parameters.py +++ b/test/python/pulse/test_parameters.py @@ -41,6 +41,7 @@ def setUp(self): self.amp = Parameter('amp') self.sigma = Parameter('sigma') self.qubit = Parameter('q') + self.dur = Parameter('dur') self.freq = 4.5e9 self.shift = 0.2e9 @@ -72,6 +73,18 @@ def test_parameter_attribute_instruction(self): self.assertFalse(inst.is_parameterized()) self.assertEqual(inst.parameters, set()) + def test_parameter_attribute_play(self): + """Test the ``parameter`` attributes.""" + inst = pulse.Play(pulse.Gaussian(self.dur, self.amp, self.sigma), + pulse.DriveChannel(self.qubit)) + self.assertTrue(inst.is_parameterized()) + self.assertSetEqual(inst.parameters, {self.dur, self.amp, self.sigma, self.qubit}) + + inst = pulse.Play(pulse.Gaussian(self.dur, 0.1, self.sigma), + pulse.DriveChannel(self.qubit)) + self.assertTrue(inst.is_parameterized()) + self.assertSetEqual(inst.parameters, {self.dur, self.sigma, self.qubit}) + def test_parameter_attribute_schedule(self): """Test the ``parameter`` attributes.""" schedule = pulse.Schedule()