Repository: Qiskit/qiskit

Issue:
Pulse schedule children should not be exposed to user
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->

### What is the expected enhancement?
The pulse schedule method should be hidden from users as this exposes the internal pulse schedule layout which may change in the future.




Discussion:

Resolving patch:
diff --git a/qiskit/pulse/commands/instruction.py b/qiskit/pulse/commands/instruction.py
--- a/qiskit/pulse/commands/instruction.py
+++ b/qiskit/pulse/commands/instruction.py
@@ -95,7 +95,7 @@ def buffer(self) -> int:
         return self._buffer
 
     @property
-    def children(self) -> Tuple[ScheduleComponent]:
+    def _children(self) -> Tuple[ScheduleComponent]:
         """Instruction has no child nodes. """
         return ()
 
diff --git a/qiskit/pulse/interfaces.py b/qiskit/pulse/interfaces.py
--- a/qiskit/pulse/interfaces.py
+++ b/qiskit/pulse/interfaces.py
@@ -86,8 +86,8 @@ def timeslots(self) -> TimeslotCollection:
 
     @property
     @abstractmethod
-    def children(self) -> Tuple[Union[int, 'ScheduleComponent']]:
-        """Child nodes of this schedule component."""
+    def _children(self) -> Tuple[Union[int, 'ScheduleComponent']]:
+        """Child nodes of this schedule component. """
         pass
 
     @property
diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py
--- a/qiskit/pulse/schedule.py
+++ b/qiskit/pulse/schedule.py
@@ -47,7 +47,7 @@ def __init__(self, *schedules: List[Union[ScheduleComponent, Tuple[int, Schedule
         self._name = name
         try:
             timeslots = []
-            children = []
+            _children = []
             for sched_pair in schedules:
                 # recreate as sequence starting at 0.
                 if not isinstance(sched_pair, (list, tuple)):
@@ -59,11 +59,11 @@ def __init__(self, *schedules: List[Union[ScheduleComponent, Tuple[int, Schedule
                 if insert_time:
                     sched_timeslots = sched_timeslots.shift(insert_time)
                 timeslots.append(sched_timeslots.timeslots)
-                children.append(sched_pair)
+                _children.append(sched_pair)
 
             self._timeslots = TimeslotCollection(*itertools.chain(*timeslots))
-            self._children = tuple(children)
-            self._buffer = max([child.buffer for _, child in children]) if children else 0
+            self.__children = tuple(_children)
+            self._buffer = max([child.buffer for _, child in _children]) if _children else 0
 
         except PulseError as ts_err:
             raise PulseError('Child schedules {0} overlap.'.format(schedules)) from ts_err
@@ -98,8 +98,8 @@ def channels(self) -> Tuple[Channel]:
         return self.timeslots.channels
 
     @property
-    def children(self) -> Tuple[ScheduleComponent]:
-        return self._children
+    def _children(self) -> Tuple[ScheduleComponent]:
+        return self.__children
 
     @property
     def instructions(self) -> Tuple[Tuple[int, 'Instruction']]:
@@ -140,7 +140,7 @@ def _instructions(self, time: int = 0) -> Iterable[Tuple[int, 'Instruction']]:
             Tuple[int, ScheduleComponent]: Tuple containing time `ScheduleComponent` starts
                 at and the flattened `ScheduleComponent`.
         """
-        for insert_time, child_sched in self.children:
+        for insert_time, child_sched in self._children:
             yield from child_sched._instructions(time + insert_time)
 
     def union(self, *schedules: List[ScheduleComponent], name: str = None) -> 'Schedule':


Test patch:
diff --git a/test/python/pulse/test_schedule.py b/test/python/pulse/test_schedule.py
--- a/test/python/pulse/test_schedule.py
+++ b/test/python/pulse/test_schedule.py
@@ -174,7 +174,7 @@ def test_empty_schedule(self):
         self.assertEqual(0, sched.start_time)
         self.assertEqual(0, sched.stop_time)
         self.assertEqual(0, sched.duration)
-        self.assertEqual((), sched.children)
+        self.assertEqual((), sched._children)
         self.assertEqual(TimeslotCollection(), sched.timeslots)
         self.assertEqual([], list(sched.instructions))
 
@@ -235,21 +235,21 @@ def test_shift_schedule(self):
         self.assertEqual([100, 130, 140], start_times)
 
     def test_keep_original_schedule_after_attached_to_another_schedule(self):
-        """Test if a schedule keeps its children after attached to another schedule."""
+        """Test if a schedule keeps its _children after attached to another schedule."""
         device = self.two_qubit_device
 
         acquire = Acquire(10)
-        children = (acquire(device.q[1], device.mem[1]).shift(20) +
-                    acquire(device.q[1], device.mem[1]))
-        self.assertEqual(2, len(list(children.instructions)))
+        _children = (acquire(device.q[1], device.mem[1]).shift(20) +
+                     acquire(device.q[1], device.mem[1]))
+        self.assertEqual(2, len(list(_children.instructions)))
 
-        sched = acquire(device.q[1], device.mem[1]).append(children)
+        sched = acquire(device.q[1], device.mem[1]).append(_children)
         self.assertEqual(3, len(list(sched.instructions)))
 
-        # add 2 instructions to children (2 instructions -> 4 instructions)
-        children = children.append(acquire(device.q[1], device.mem[1]))
-        children = children.insert(100, acquire(device.q[1], device.mem[1]))
-        self.assertEqual(4, len(list(children.instructions)))
+        # add 2 instructions to _children (2 instructions -> 4 instructions)
+        _children = _children.append(acquire(device.q[1], device.mem[1]))
+        _children = _children.insert(100, acquire(device.q[1], device.mem[1]))
+        self.assertEqual(4, len(list(_children.instructions)))
         # sched must keep 3 instructions (must not update to 5 instructions)
         self.assertEqual(3, len(list(sched.instructions)))
 
@@ -296,7 +296,7 @@ def test_flatten(self):
 
         flat_sched = sched.flatten()
 
-        self.assertEqual(len(flat_sched.children), 10)
+        self.assertEqual(len(flat_sched._children), 10)
 
         self.assertEqual(flat_sched.instructions, sched.instructions)