Repository: Qiskit/qiskit (python)

Issue:
`pulse.build()` raises an error when `default_alignment` is set to `AlignmentKind` instance
### Environment

- **Qiskit version**: main
- **Python version**: 3.9
- **Operating system**: windows


### What is happening?

`pulse.build()` raises an error when `default_alignment` is set to `AlignmentKind` instance.

### How can we reproduce the issue?

```python
from qiskit.pulse import build
from qiskit.pulse.transforms import AlignLeft

with build(default_alignment=AlignLeft()) as schblock:
  pass

### What should happen?

The builder should accept the `AlignmentKind` instance as valid input, and set it as the default alignment.

### Any suggestions?

This [line](https://github.com/Qiskit/qiskit/blob/8557369597c7c7f3a0abe3f8b07045752ec10061/qiskit/pulse/builder.py#L534) assumes string identifier input, and ignores the possibility of `AlignmentKind` instance input.

Pull request description:
Fix `pulse.build()` default alignment argument
### Summary
Fix #12028 such that `pulse.build()` will accept `AlignmentKind` instances as valid input for argument `default_alignment`.





Patch:
diff --git a/qiskit/pulse/builder.py b/qiskit/pulse/builder.py
index 6d57c2e3c..b7bdbe85c 100644
--- a/qiskit/pulse/builder.py
+++ b/qiskit/pulse/builder.py
@@ -531,7 +531,10 @@ class _PulseBuilder:
             self._context_stack.append(root_block)
 
         # Set default alignment context
-        alignment = _PulseBuilder.__alignment_kinds__.get(default_alignment, default_alignment)
+        if isinstance(default_alignment, AlignmentKind):  # AlignmentKind instance
+            alignment = default_alignment
+        else:  # str identifier
+            alignment = _PulseBuilder.__alignment_kinds__.get(default_alignment, default_alignment)
         if not isinstance(alignment, AlignmentKind):
             raise exceptions.PulseError(
                 f"Given `default_alignment` {repr(default_alignment)} is "
diff --git a/releasenotes/notes/fix-pulse-builder-default-alingment-52f81224d90c21e2.yaml b/releasenotes/notes/fix-pulse-builder-default-alingment-52f81224d90c21e2.yaml
new file mode 100644
index 000000000..b8d775e82
--- /dev/null
+++ b/releasenotes/notes/fix-pulse-builder-default-alingment-52f81224d90c21e2.yaml
@@ -0,0 +1,6 @@
+---
+fixes:
+  - |
+    Fixed a bug in the handling of ``default_alignment`` argument of :func:`~qiskit.pulse.build`.
+    Inputs of type :class:`~qiskit.pulse.transforms.AlignmentKind` are now correctly processed as
+    default alignments.


Test patch:
diff --git a/test/python/pulse/test_builder.py b/test/python/pulse/test_builder.py
index 6ec508976..cf029d5d9 100644
--- a/test/python/pulse/test_builder.py
+++ b/test/python/pulse/test_builder.py
@@ -21,6 +21,7 @@ from qiskit.pulse.instructions import directives
 from qiskit.pulse.transforms import target_qobj_transform
 from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake127QPulseV1
 from qiskit.pulse import library, instructions
+from qiskit.pulse.exceptions import PulseError
 from test import QiskitTestCase  # pylint: disable=wrong-import-order
 
 
@@ -106,6 +107,29 @@ class TestBuilderBase(TestBuilder):
 
         self.assertScheduleEqual(schedule, reference)
 
+    def test_default_alignment_alignmentkind_instance(self):
+        """Test default AlignmentKind instance"""
+        d0 = pulse.DriveChannel(0)
+        d1 = pulse.DriveChannel(0)
+
+        with pulse.build(default_alignment=pulse.transforms.AlignEquispaced(100)) as schedule:
+            pulse.delay(10, d0)
+            pulse.delay(20, d1)
+
+        with pulse.build() as reference:
+            with pulse.align_equispaced(100):
+                pulse.delay(10, d0)
+                pulse.delay(20, d1)
+
+        self.assertScheduleEqual(schedule, reference)
+
+    def test_unknown_string_identifier(self):
+        """Test that unknown string identifier raises an error"""
+
+        with self.assertRaises(PulseError):
+            with pulse.build(default_alignment="unknown") as _:
+                pass
+
 
 class TestContexts(TestBuilder):
     """Test builder contexts."""