Repository: Qiskit/qiskit-terra (python)

Issue:
Add BackendV2 support for `transpiler._parse_inst_map()`
### What should we add?

BackendV2 has removed `defaults` attribute from backend and `transpiler._parse_inst_map()` needs to be updated to support BackendV2.

https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/compiler/transpiler.py#L666-L676
```python
def _parse_inst_map(inst_map, backend, num_circuits):
    # try getting inst_map from user, else backend
    if inst_map is None:
        if hasattr(backend, "defaults"):
            inst_map = getattr(backend.defaults(), "instruction_schedule_map", None)

    # inst_maps could be None, or single entry
    if inst_map is None or isinstance(inst_map, InstructionScheduleMap):
        inst_map = [inst_map] * num_circuits

    return inst_map
```

This was discovered in #7643. Created as a issue with separate PR to follow by @mtreinish https://github.com/Qiskit/qiskit-terra/pull/7643/files/474e529c55e8198493512a02c4df52966ad83063#r823983767

Pull request description:
Add transpile() support for extracting instruction schedule map from BackendV2
<!--
⚠️ If you do not respect this template, your pull request will be closed.
⚠️ Your pull request title should be short detailed and understandable for all.
⚠️ Also, please add a release note file using reno if the change needs to be
  documented in the release notes.
⚠️ If your pull request fixes an open issue, please link to the issue.

- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the CONTRIBUTING document.
-->

### Summary

BackendV2 has removed `defaults` attribute from backend and `transpiler._parse_inst_map()` needs to be updated to support BackendV2. (#7764) This PR address this issue.

To do
- [x] Add test
- [x] Add release note

Fixes #7764 

### Details and comments




Patch:
diff --git a/qiskit/compiler/transpiler.py b/qiskit/compiler/transpiler.py
index c63b3f825..f322935fe 100644
--- a/qiskit/compiler/transpiler.py
+++ b/qiskit/compiler/transpiler.py
@@ -666,9 +666,14 @@ def _parse_basis_gates(basis_gates, backend, circuits):
 def _parse_inst_map(inst_map, backend, num_circuits):
     # try getting inst_map from user, else backend
     if inst_map is None:
-        if hasattr(backend, "defaults"):
-            inst_map = getattr(backend.defaults(), "instruction_schedule_map", None)
-
+        backend_version = getattr(backend, "version", 0)
+        if not isinstance(backend_version, int):
+            backend_version = 0
+        if backend_version <= 1:
+            if hasattr(backend, "defaults"):
+                inst_map = getattr(backend.defaults(), "instruction_schedule_map", None)
+        else:
+            inst_map = backend.target.instruction_schedule_map()
     # inst_maps could be None, or single entry
     if inst_map is None or isinstance(inst_map, InstructionScheduleMap):
         inst_map = [inst_map] * num_circuits
diff --git a/releasenotes/notes/add-v2-backend-support-in-transpiler-parse-inst-map-a617801850178d05.yaml b/releasenotes/notes/add-v2-backend-support-in-transpiler-parse-inst-map-a617801850178d05.yaml
new file mode 100644
index 000000000..1860f16c0
--- /dev/null
+++ b/releasenotes/notes/add-v2-backend-support-in-transpiler-parse-inst-map-a617801850178d05.yaml
@@ -0,0 +1,7 @@
+---
+fixes:
+  - |
+    Fixed support in :func:`~qiskit.compiler.transpile` for passing a
+    :class:`~qiskit.pulse.InstructionMap` to the underlying :class:`~qiskit.transpiler.PassManager`
+    based on the :class:`~qiskit.transpiler.Target` for :class:`~qiskit.providers.backend.BackendV2` based
+    backends.


Test patch:
diff --git a/test/python/providers/test_backend_v2.py b/test/python/providers/test_backend_v2.py
index 0f9d0204a..22a33b11d 100644
--- a/test/python/providers/test_backend_v2.py
+++ b/test/python/providers/test_backend_v2.py
@@ -21,6 +21,8 @@ from ddt import ddt, data
 
 from qiskit.circuit import QuantumCircuit, ClassicalRegister, QuantumRegister
 from qiskit.compiler import transpile
+from qiskit.compiler.transpiler import _parse_inst_map
+from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap
 from qiskit.test.base import QiskitTestCase
 from qiskit.test.mock.fake_backend_v2 import FakeBackendV2, FakeBackend5QV2
 from qiskit.test.mock.fake_mumbai_v2 import FakeMumbaiV2
@@ -165,3 +167,8 @@ class TestBackendV2(QiskitTestCase):
         expected.measure(qr[0], cr[0])
         expected.measure(qr[1], cr[1])
         self.assertEqual(expected, tqc)
+
+    def test_transpile_parse_inst_map(self):
+        """Test that transpiler._parse_inst_map() supports BackendV2."""
+        inst_map = _parse_inst_map(inst_map=None, backend=self.backend, num_circuits=1)[0]
+        self.assertIsInstance(inst_map, InstructionScheduleMap)