Repository: Qiskit/qiskit

Issue:
`optimization_level=0` and `optimization_level=1` raise different error when too-large circuit and disjoint connectivity
### Environment

- **Qiskit Terra version**: 0.45.0.dev0+571cd8a
- **Python version**: 3.9
- **Operating system**: MacOs 


### What is happening?

When transpiling a 6-long qubit circuit in a disjointed target (say 3+3), the errors with `optimization_level=0` and `optimization_level=1` are different. I think it should be the same one (even when might had been detected in different places of Qiskit)

### How can we reproduce the issue?

```python
from qiskit.circuit.library import QuantumVolume
from qiskit.compiler import transpile

circuit_in = QuantumVolume(6, depth=1, seed=42).decompose().decompose()
circuit_in.measure_all()

from qiskit.compiler import transpile

transpiled = transpile(circuit_in, seed_transpiler=42, coupling_map=[[0,1],[1,2],[2,0],[3,4],[4,5],[5,3]], optimization_level=0)
```
```
TranspilerError: 'Chosen layout is not valid for the target disjoint connectivity'
```
However, with `transpiled = transpile(circuit_in, seed_transpiler=42, coupling_map=[[0,1],[1,2],[2,0],[3,4],[4,5],[5,3]], optimization_level=1)`:
```
TranspilerError: 'A connected component of the DAGCircuit is too large for any of the connected components in the coupling map.'
```

### What should happen?

The error for `optimization_level=0` looks to me a bit more obscure. I think raising the same error is important to better guide the user. 

### Any suggestions?

_No response_


Discussion:
The errors are actually different though, it's a subtlety in how level 0 works. For level 0 it runs trivial layout which is successful and the layout is applied to the circuit because it is unaware of the coupling map connectivity in its operation (it just maps 0->0, 1->1, etc). Then when it reaches routing that fails because there is a path needed between connected components where that isn't possible, which is what the error says. This is the same error you'd get if you set `initial_layout` and it wasn't a good layout. For level 1 it is different because it runs sabre layout which looks at the connectivity and determines that a suitable layout is not feasible for the backend and errors accordingly.
That being said we can change the error message text fairly easily it lives here https://github.com/Qiskit/qiskit/blob/main/qiskit/transpiler/passes/layout/disjoint_utils.py#L167 the message that comes from a layout pass failure is in the same module too.
Fwiw we discussed this strategy of "what level 0 means" in the compiler meeting before the disjoint-coupling support merged, and the general consensus (as best I remember it) was that level 0 is effectively saying "use this layout we're giving you" (the trivial layout / initial layout) as opposed to other levels that are saying "find a good layout for me".  The error messages reflect that, but it's certainly possible that the decision could/should have been different.
oh! I see. Thanks for the explanation.


Indeed, a 3-long QV may raise too with level 0. For example: 

![image](https://github.com/Qiskit/qiskit/assets/766693/17fabc57-7164-43d2-add1-6116e6424b12)

```python
from qiskit.circuit.library import QuantumVolume
from qiskit.compiler import transpile

circuit_in = QuantumVolume(3, depth=1, seed=42).decompose().decompose()
from qiskit.compiler import transpile

transpiled = transpile(circuit_in, seed_transpiler=42, coupling_map=[[3,1],[1,2],[2,3],[0,4],[4,5],[5,0]], optimization_level=0)
```
```
TranspilerError: 'Chosen layout is not valid for the target disjoint connectivity'
```

I agree, they are indeed two different errors.

Maybe `Chosen layout is not valid for the target disjoint connectivity` is a bit confusing as I did not choose any layout. Let me have another thought to see if the message can be improved.

Resolving patch:
diff --git a/qiskit/transpiler/passes/layout/disjoint_utils.py b/qiskit/transpiler/passes/layout/disjoint_utils.py
--- a/qiskit/transpiler/passes/layout/disjoint_utils.py
+++ b/qiskit/transpiler/passes/layout/disjoint_utils.py
@@ -164,7 +164,12 @@ def require_layout_isolated_to_component(
                 component_index = i
                 break
         if dag.find_bit(inst.qargs[1]).index not in component_sets[component_index]:
-            raise TranspilerError("Chosen layout is not valid for the target disjoint connectivity")
+            raise TranspilerError(
+                "The circuit has an invalid layout as two qubits need to interact in disconnected "
+                "components of the coupling map. The physical qubit "
+                f"{dag.find_bit(inst.qargs[1]).index} needs to interact with the "
+                f"qubit {dag.find_bit(inst.qargs[0]).index} and they belong to different components"
+            )
 
 
 def separate_dag(dag: DAGCircuit) -> List[DAGCircuit]:


Test patch: