Skip to content

Commit

Permalink
* Added check to ensure that all parameter names in a schedule are un…
Browse files Browse the repository at this point in the history
…ique.

* Removed the erroneous check in register_parameter.
  • Loading branch information
eggerdj committed Apr 14, 2021
1 parent f74534e commit 72ce1c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
17 changes: 7 additions & 10 deletions qiskit_experiments/calibration/calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def add_schedules(self, schedules: Union[Schedule, List[Schedule]]):
Raises:
CalibrationError: If the parameterized channel index is not formatted
following index1.index2...
following index1.index2... or if several parameters in the same schedule
have the same name.
"""
if isinstance(schedules, Schedule):
schedules = [schedules]
Expand All @@ -84,6 +85,11 @@ def add_schedules(self, schedules: Union[Schedule, List[Schedule]]):

self._schedules[schedule.name] = schedule

param_names = [param.name for param in schedule.parameters]

if len(param_names) != len(set(param_names)):
raise CalibrationError(f"Parameter names in {schedule.name} must be unique.")

for param in schedule.parameters:
self.register_parameter(param, schedule)

Expand All @@ -95,17 +101,8 @@ def register_parameter(self, parameter: Parameter, schedule: Schedule = None):
parameter: The parameter to register.
schedule: The Schedule to which this parameter belongs. The schedule can
be None which implies a global parameter.
Raises:
CalibrationError: if a parameter with the same name was already registered
for the given schedule.
"""
sched_name = schedule.name if schedule else None
if (sched_name, parameter.name) in self._parameter_map:
raise CalibrationError(
f"Parameter with name {parameter.name} is not unique in schedule {sched_name}."
)

self._parameter_map[ParameterKey(sched_name, parameter.name)] = parameter
if parameter not in self._params:
self._params[parameter] = {}
Expand Down
4 changes: 0 additions & 4 deletions test/calibration/test_calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,3 @@ def test_unique_parameter_names(self):
def test_parameter_without_schedule(self):
"""Test that we can manage parameters that are not bound to a schedule."""
self.cals.register_parameter(Parameter('a'))

# Check that we cannot register the same parameter twice.
with self.assertRaises(CalibrationError):
self.cals.register_parameter(Parameter('a'))

0 comments on commit 72ce1c0

Please sign in to comment.