Repository: Qiskit/qiskit

Issue:
Invalid QASM error with a very simple circuit.
QISKit 0.4.13 seems to generate an invalid QASM for real devices.

## Expected Behavior
QISKit executes the circuit without error.
```
from qiskit import QuantumProgram
import Qconfig
qp = QuantumProgram()
qp.set_api(Qconfig.APItoken, Qconfig.config['url'])
qr = qp.create_quantum_register('qr',1)
cr = qp.create_classical_register('cr',1)
qc = qp.create_circuit('sample',[qr],[cr])
qc.h(qr[0])
result = qp.execute('sample', backend='ibmqx4')
print(result.get_counts('sample'))
```
https://gist.github.com/t-imamichi/f4afd05e7b510f2ab259bca68f44c022

## Current Behavior
```
WARNING:IBMQuantumExperience.IBMQuantumExperience:Got a 400 code response to https://quantumexperience.ng.bluemix.net/api/Jobs?access_token=XXX: {"error":{"status":400,"message":"Error parsing QASM. Error parsing qasm number 0. Identifiers must begin with a lowercase letter","code":"QASM_NOT_VALID","statusCode":400}}
qiskit._resulterror.ResultError: QASM_NOT_VALID: Error parsing QASM. Error parsing qasm number 0. Identifiers must begin with a lowercase letter
```

## Possible Solution
no idea.

## Steps to Reproduce (for bugs)
https://gist.github.com/t-imamichi/f4afd05e7b510f2ab259bca68f44c022
1. Set Qconfig appropriately
2. Run the script
3.
4.

## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->

## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
* Version used: qiskit 0.4.13
* Environment name and version (e.g. Python 3.6.1): Python 3.6.5
* Operating System and version: Ubuntu 16.04


Discussion:

Resolving patch:
diff --git a/qiskit/backends/_backendutils.py b/qiskit/backends/_backendutils.py
--- a/qiskit/backends/_backendutils.py
+++ b/qiskit/backends/_backendutils.py
@@ -110,7 +110,7 @@ def discover_remote_backends(api):
             if new_key not in ['id', 'serial_number', 'topology_id', 'status']:
                 config_edit[new_key] = config[key]
         # online_qasm_simulator uses different name for basis_gates
-        if 'gateSet' in config:
+        if 'gateSet' in config and 'basisGates' not in config:
             config_edit['basis_gates'] = config['gateSet']
             del config_edit['gate_set']
         # ibmqx_qasm_simulator doesn't report coupling_map


Test patch:
diff --git a/test/python/test_backends.py b/test/python/test_backends.py
--- a/test/python/test_backends.py
+++ b/test/python/test_backends.py
@@ -101,6 +101,8 @@ def test_get_backend_configuration_online(self, QE_TOKEN, QE_URL):
         backend_list = qiskit.backends.discover_remote_backends(api)
         config_keys = {'name', 'simulator', 'local', 'description',
                        'coupling_map', 'basis_gates'}
+        backend_list.remove('ibmqx_hpc_qasm_simulator')
+        backend_list.remove('ibmqx_qasm_simulator')
         if backend_list:
             backend = backend_list[0]
         my_backend = qiskit.backends.get_backend_instance(backend)
@@ -116,6 +118,8 @@ def test_get_backend_calibration(self, QE_TOKEN, QE_URL):
         """
         api = IBMQuantumExperience(QE_TOKEN, {'url': QE_URL})
         backend_list = qiskit.backends.discover_remote_backends(api)
+        backend_list.remove('ibmqx_hpc_qasm_simulator')
+        backend_list.remove('ibmqx_qasm_simulator')
         if backend_list:
             backend = backend_list[0]
         my_backend = qiskit.backends.get_backend_instance(backend)
@@ -131,6 +135,8 @@ def test_get_backend_parameters(self, QE_TOKEN, QE_URL):
         """
         api = IBMQuantumExperience(QE_TOKEN, {'url': QE_URL})
         backend_list = qiskit.backends.discover_remote_backends(api)
+        backend_list.remove('ibmqx_hpc_qasm_simulator')
+        backend_list.remove('ibmqx_qasm_simulator')
         if backend_list:
             backend = backend_list[0]
         my_backend = qiskit.backends.get_backend_instance(backend)
diff --git a/test/python/test_quantumprogram.py b/test/python/test_quantumprogram.py
--- a/test/python/test_quantumprogram.py
+++ b/test/python/test_quantumprogram.py
@@ -672,6 +672,8 @@ def test_get_backend_configuration_online(self, QE_TOKEN, QE_URL):
                        'coupling_map', 'basis_gates'}
         api = IBMQuantumExperience(QE_TOKEN, {'url': QE_URL})
         backend_list = qiskit.backends.discover_remote_backends(api)
+        backend_list.remove('ibmqx_hpc_qasm_simulator')
+        backend_list.remove('ibmqx_qasm_simulator')
         if backend_list:
             backend = backend_list[0]
         backend_config = qp.get_backend_configuration(backend)
@@ -697,6 +699,8 @@ def test_get_backend_calibration(self, QE_TOKEN, QE_URL):
         q_program = QuantumProgram(specs=self.QPS_SPECS)
         api = IBMQuantumExperience(QE_TOKEN, {'url': QE_URL})
         backend_list = qiskit.backends.discover_remote_backends(api)
+        backend_list.remove('ibmqx_hpc_qasm_simulator')
+        backend_list.remove('ibmqx_qasm_simulator')
         if backend_list:
             backend = backend_list[0]
         result = q_program.get_backend_calibration(backend)
@@ -713,6 +717,8 @@ def test_get_backend_parameters(self, QE_TOKEN, QE_URL):
         q_program = QuantumProgram(specs=self.QPS_SPECS)
         api = IBMQuantumExperience(QE_TOKEN, {'url': QE_URL})
         backend_list = qiskit.backends.discover_remote_backends(api)
+        backend_list.remove('ibmqx_hpc_qasm_simulator')
+        backend_list.remove('ibmqx_qasm_simulator')
         if backend_list:
             backend = backend_list[0]
         result = q_program.get_backend_parameters(backend)