Repository: Qiskit/qiskit

Issue:
optimize_1q_decomposition: 'NoneType' object has no attribute 'global_phase'
### Environment

- **Qiskit Terra version**: 0.24.0.dev0+84a0fdd
- **Python version**:  3.9
- **Operating system**:  MacOS


### What is happening?

When `unitary_synthesis` is called with a particularly restrictive `basis_gates`, it seems to generate a `None` output as `best_synth_circuit`, which makes `optimize_1q_decomposition` raise. 

### How can we reproduce the issue?

```python
from qiskit import *
circuit = QuantumCircuit(1)
circuit.append(Operator([[0.96891242+0.j        , 0.        -0.24740396j],
          [0.        -0.24740396j, 0.96891242+0.j        ]]), [0])
transpile(circuit, basis_gates=['h', 'rx']).draw()
```
```
...
<reducted>/qiskit/transpiler/passes/synthesis/unitary_synthesis.py in run(self, unitary, **options)
    741         if unitary.shape == (2, 2):
    742             _decomposer1q = Optimize1qGatesDecomposition(basis_gates, target)
--> 743             return _decomposer1q._gate_sequence_to_dag(
    744                 _decomposer1q._resynthesize_run(unitary, qubits[0])
    745             )

<reducted>/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py in _gate_sequence_to_dag(self, best_synth_circuit)
    144         out_dag = DAGCircuit()
    145         out_dag.add_qubits(qubits)
--> 146         out_dag.global_phase = best_synth_circuit.global_phase
    147 
    148         for gate_name, angles in best_synth_circuit:

AttributeError: 'NoneType' object has no attribute 'global_phase'
```

### What should happen?

work or nicer error

### Any suggestions?

_No response_


Discussion:
Notice that `transpile(circuit, basis_gates=['rx', 'ry', 'rz'])` works, and returns:
```
   ┌─────────┐
q: ┤ Rx(0.5) ├
   └─────────┘
```
The immediate cause for why it doesn't work is because `['h', 'rx']` isn't a combination that we have a synthesis routine for.  There are no syntheses found, and the pass should return an error.  Of course, we should catch that case and return a good error rather than this one, though.

Resolving patch:
diff --git a/qiskit/transpiler/passes/synthesis/unitary_synthesis.py b/qiskit/transpiler/passes/synthesis/unitary_synthesis.py
--- a/qiskit/transpiler/passes/synthesis/unitary_synthesis.py
+++ b/qiskit/transpiler/passes/synthesis/unitary_synthesis.py
@@ -740,9 +740,10 @@ def run(self, unitary, **options):
 
         if unitary.shape == (2, 2):
             _decomposer1q = Optimize1qGatesDecomposition(basis_gates, target)
-            return _decomposer1q._gate_sequence_to_dag(
-                _decomposer1q._resynthesize_run(unitary, qubits[0])
-            )
+            sequence = _decomposer1q._resynthesize_run(unitary, qubits[0])
+            if sequence is None:
+                return None
+            return _decomposer1q._gate_sequence_to_dag(sequence)
         elif unitary.shape == (4, 4):
             # select synthesizers that can lower to the target
             if target is not None:


Test patch:
diff --git a/test/python/transpiler/test_unitary_synthesis.py b/test/python/transpiler/test_unitary_synthesis.py
--- a/test/python/transpiler/test_unitary_synthesis.py
+++ b/test/python/transpiler/test_unitary_synthesis.py
@@ -857,6 +857,12 @@ def __init__(self):
         result_qc = dag_to_circuit(result_dag)
         self.assertEqual(result_qc, QuantumCircuit(2))
 
+    def test_default_does_not_fail_on_no_syntheses(self):
+        qc = QuantumCircuit(1)
+        qc.unitary(np.eye(2), [0])
+        pass_ = UnitarySynthesis(["unknown", "gates"])
+        self.assertEqual(qc, pass_(qc))
+
 
 if __name__ == "__main__":
     unittest.main()