Skip to content

Commit

Permalink
Allows str as volatile argument and verify volatile parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Feb 17, 2023
1 parent 0644d25 commit f1185d9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion qupulse/pulses/pulse_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def create_program(self, *,
channel_mapping: Optional[Mapping[ChannelID, Optional[ChannelID]]]=None,
global_transformation: Optional[Transformation]=None,
to_single_waveform: Set[Union[str, 'PulseTemplate']]=None,
volatile: Set[str] = None) -> Optional['Loop']:
volatile: Union[Set[str], str] = None) -> Optional['Loop']:
"""Translates this PulseTemplate into a program Loop.
The returned Loop represents the PulseTemplate with all parameter values instantiated provided as dictated by
Expand Down Expand Up @@ -144,6 +144,10 @@ def create_program(self, *,
to_single_waveform = set()
if volatile is None:
volatile = set()
elif isinstance(volatile, str):
volatile = {volatile}
else:
volatile = set(volatile)

# make sure all channels are mapped
complete_channel_mapping = {channel: channel for channel in self.defined_channels}
Expand All @@ -167,6 +171,12 @@ def create_program(self, *,

scope = DictScope(values=FrozenDict(parameters), volatile=volatile)

for volatile_name in scope.get_volatile_parameters():
if volatile_name not in scope:
warnings.warn(f"The volatile parameter {volatile_name!r} is not in the given parameters.",
category=UnknownVolatileParameter,
stacklevel=2)

root_loop = Loop()

# call subclass specific implementation
Expand Down Expand Up @@ -531,3 +541,6 @@ def __str__(self) -> str:
self.templateA, self.templateB, ', '.join(self.names)
)


class UnknownVolatileParameter(RuntimeWarning):
pass

0 comments on commit f1185d9

Please sign in to comment.