Repository: Qiskit/qiskit

Issue:
hello_quantum.py example fails because Armonk is a 1-qubit provider
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Information

- **Qiskit Terra version**: 0.14.1
- **Python version**: 3.7.5
- **Operating system**: Linux Mint 18.3

### What is the current behavior?

When I run the  hello_quantum.py example it fails  with `qiskit.transpiler.exceptions.TranspilerError: 'Number of qubits (2) in circuit8 is greater than maximum (1) in the coupling_map'`

 because IBM Armonk is in the list of available providers and it has only one qubit, which is insufficient to run the example.

### Steps to reproduce the problem

install credentials
run `hello_quantum.py`

### What is the expected behavior?

The example should run on both the simulator and the least busy provider with sufficient qubits

### Suggested solutions

Filter providers with this code:

```def backends_with_qubits(backends, qubits):
        return [backend  for backend in backends
            if backend.configuration().n_qubits >=  qubits and
            backend.configuration().simulator == False]
```

and use it like this

```
ibmq_backends = backends_with_qubits(provider.backends(), 2)
print("Remote backends: ", ibmq_backends)
# Compile and run the Quantum Program on a real device backend
try:
    # least_busy_device = least_busy(provider.backends(simulator=False))
    least_busy_device = least_busy(ibmq_backends)
except:
    print("All devices are currently unavailable.")
print("Running on current least busy device: ", least_busy_device)
#running the job
job_exp = execute(qc, least_busy_device, shots=1024, max_credits=10)
result_exp = job_exp.result()
```

I'd be happy to submit a PR to the example if that would be useful, but maybe Armonk should not be in the list of available backends.






Discussion:
Sure, please feel free to push a pull request to update the example. One suggestion I'd make on your example is to do some thing like:

```python
least_busy_device = least_busy(provider.backends(
    filters=lambda x: x.configuration().n_qubits >= 2, simulator=False)
```

instead of manually filtering in a separate function, just to keep the example simpler.

The ibmq provider uses https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/providers/providerutils.py#L22 which lets you pass a callable filter (in addition to filtering on configuration or status).
Great, thanks. I should have spotted the filter :)

PR to follow shortly.

On Thu, 28 May 2020 at 14:34, Matthew Treinish <notifications@github.com>
wrote:

> Sure, please feel free to push a pull request to update the example. One
> suggestion I'd make on your example is to do some thing like:
>
> least_busy_device = least_busy(provider.backends(
>     filters=lambda x: x.configuration().n_qubits >= 2, simulator=False)
>
> instead of manually filtering in a separate function, just to keep the
> example simpler.
>
> The ibmq provider uses
> https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/providers/providerutils.py#L22
> which lets you pass a callable filter (in addition to filtering on
> configuration or status).
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/Qiskit/qiskit-terra/issues/4510#issuecomment-635353309>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AABEOPQ5LYESOGKGM7YBQCDRTZR5TANCNFSM4NM6DBFQ>
> .
>


-- 
personal:@romillyc work:@rareblog skype:romilly.cocking web:
http://blog.rareschool.com/


Resolving patch:
diff --git a/examples/python/ibmq/hello_quantum.py b/examples/python/ibmq/hello_quantum.py
--- a/examples/python/ibmq/hello_quantum.py
+++ b/examples/python/ibmq/hello_quantum.py
@@ -55,8 +55,10 @@
 
 print("Remote backends: ", ibmq_backends)
 # Compile and run the Quantum Program on a real device backend
+# select those with at least 2 qubits
 try:
-    least_busy_device = least_busy(provider.backends(simulator=False))
+    least_busy_device = least_busy(provider.backends(
+        filters=lambda x: x.configuration().n_qubits >= 2, simulator=False))
 except:
     print("All devices are currently unavailable.")
 


Test patch: