internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: Qiskit/qiskit

Issue:
Spurious `Error: cannot import name 'load_qasm_file`
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

When importing qiskit from current master, an error is printed, even if the function can actually be imported and used correctly.


- **Qiskit Terra version**: master 83085edb374a3e26175bfc408ea293fdfb76aeb4
- **Python version**:
- **Operating system**:

### What is the current behavior?

```
In [1]: import qiskit
Error: cannot import name 'load_qasm_file'

In [2]: qiskit.load_qasm_file
Out[2]: <function qiskit.wrapper._wrapper.load_qasm_file(qasm_file, name=None, basis_gates='id,u0,u1,u2,u3,x,y,z,h,s,sdg,t,tdg,rx,ry,rz,cx,cy,cz,ch,crz,cu1,cu3,swap,ccx,cswap')>
```

### Suggested solutions

This seems to be related to the order of imports in `qiskit/__init__.py` introduced in  #874, which rippled back silently after #885 . The error message is printed during the import of `circuit_drawer`, as it tries to import `qiskit.load_qasm_string`, which is not available by that time.




Discussion:

Resolving patch:
diff --git a/qiskit/__init__.py b/qiskit/__init__.py
--- a/qiskit/__init__.py
+++ b/qiskit/__init__.py
@@ -37,6 +37,12 @@
 # to be placed *before* the wrapper imports or any non-import code.
 __path__ = pkgutil.extend_path(__path__, __name__)
 
+from .wrapper._wrapper import (
+    available_backends, local_backends, remote_backends,
+    get_backend, compile, execute, register, unregister,
+    registered_providers, load_qasm_string, load_qasm_file, least_busy,
+    store_credentials)
+
 # Import circuit drawing methods by default
 # This is wrapped in a try because the Travis tests fail due to non-framework
 # Python build since using pyenv
@@ -45,12 +51,6 @@
 except (ImportError, RuntimeError) as expt:
     print("Error: {0}".format(expt))
 
-from .wrapper._wrapper import (
-    available_backends, local_backends, remote_backends,
-    get_backend, compile, execute, register, unregister,
-    registered_providers, load_qasm_string, load_qasm_file, least_busy,
-    store_credentials)
-
 # Import the wrapper, to make it available when doing "import qiskit".
 from . import wrapper
 
diff --git a/qiskit/tools/visualization/_circuit_visualization.py b/qiskit/tools/visualization/_circuit_visualization.py
--- a/qiskit/tools/visualization/_circuit_visualization.py
+++ b/qiskit/tools/visualization/_circuit_visualization.py
@@ -31,7 +31,9 @@
 from matplotlib import get_backend as get_matplotlib_backend, \
     patches as patches, pyplot as plt
 
-from qiskit import QuantumCircuit, QISKitError, load_qasm_file
+from qiskit._qiskiterror import QISKitError
+from qiskit._quantumcircuit import QuantumCircuit
+from qiskit.wrapper import load_qasm_file
 
 from qiskit.dagcircuit import DAGCircuit
 from qiskit.transpiler import transpile


Test patch:
Repository: Qiskit/qiskit

Issue:
Loading Qiskit with no internet results in a ConnectionError
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### What is the current behavior?
Loading Qiskit with no Internet results in a `ConnectionError`.

### Steps to reproduce the problem
Run Qiskit without Internet connection.

### What is the expected behavior?
Qiskit prompt no error at all.





Discussion:

Resolving patch:
diff --git a/qiskit/_util.py b/qiskit/_util.py
--- a/qiskit/_util.py
+++ b/qiskit/_util.py
@@ -13,6 +13,7 @@
 import re
 import sys
 import warnings
+import socket
 from collections import UserDict
 
 API_NAME = 'IBMQuantumExperience'
@@ -157,3 +158,26 @@ def _parse_ibmq_credentials(url, hub=None, group=None, project=None):
             "0.6+. Please use the new URL format provided in the q-console.",
             DeprecationWarning)
     return url
+
+
+def _has_connection(hostname, port):
+    """Checks to see if internet connection exists to host
+    via specified port
+
+    Args:
+        hostname (str): Hostname to connect to.
+        port (int): Port to connect to
+
+    Returns:
+        bool: Has connection or not
+
+    Raises:
+        gaierror: No connection established.
+    """
+    try:
+        host = socket.gethostbyname(hostname)
+        socket.create_connection((host, port), 2)
+        return True
+    except socket.gaierror:
+        pass
+    return False
diff --git a/qiskit/tools/visualization/__init__.py b/qiskit/tools/visualization/__init__.py
--- a/qiskit/tools/visualization/__init__.py
+++ b/qiskit/tools/visualization/__init__.py
@@ -8,7 +8,7 @@
 """Main QISKit visualization methods."""
 
 import sys
-
+from qiskit._util import _has_connection
 from ._circuit_visualization import circuit_drawer, plot_circuit, generate_latex_source,\
     latex_circuit_drawer, matplotlib_circuit_drawer, qx_color_scheme
 from ._error import VisualizationError
@@ -16,9 +16,7 @@
 
 
 if ('ipykernel' in sys.modules) and ('spyder' not in sys.modules):
-    import requests
-    if requests.get(
-            'https://qvisualization.mybluemix.net/').status_code == 200:
+    if _has_connection('https://qvisualization.mybluemix.net/', 443):
         from .interactive._iplot_state import iplot_state as plot_state
         from .interactive._iplot_histogram import iplot_histogram as \
             plot_histogram


Test patch:
Repository: Qiskit/qiskit

Issue:
Aqua GUI interface crashes for default OSX matplotlib backend.
@nonhermitian noted in #903:

### What is the current behavior?
Aqua GUI interface crashes for default OSX matplotlib backend.


Discussion:

Resolving patch:
diff --git a/qiskit/__init__.py b/qiskit/__init__.py
--- a/qiskit/__init__.py
+++ b/qiskit/__init__.py
@@ -43,14 +43,6 @@
     registered_providers, load_qasm_string, load_qasm_file, least_busy,
     store_credentials)
 
-# Import circuit drawing methods by default
-# This is wrapped in a try because the Travis tests fail due to non-framework
-# Python build since using pyenv
-try:
-    from qiskit.tools.visualization import (circuit_drawer, plot_histogram)
-except (ImportError, RuntimeError) as expt:
-    print("Error: {0}".format(expt))
-
 # Import the wrapper, to make it available when doing "import qiskit".
 from . import wrapper
 


Test patch:
Repository: Qiskit/qiskit

Issue:
Latex circuit drawer fails when barrier is present.
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

- **Qiskit Terra version**: latest master
- **Python version**: 3.7
- **Operating system**: OSX

### What is the current behavior?
Using `circuit_drawer` on a circuit with a barrier fails:

```python
q = QuantumRegister(2, "q")
qc = QuantumCircuit(q)
qc.cx(q[0],q[1])
qc.barrier(q)
circuit_drawer(qc)
```
giving the following log report:
```
<xymatrix
! Undefined control sequence.
<recently read> \barrier 
```


### Steps to reproduce the problem



### What is the expected behavior?



### Suggested solutions





Discussion:
You need to update your version of the qcircuit latex package to the latest version, 2.6.0 (which added the \barrier command). You can find the latest version on CTAN: https://ctan.org/pkg/qcircuit if the version of texlive packaged on osx doesn't include that version yet.
Hopefully this is documented somewhere.
Yes, this is fixed when updating to 2.6.0.  However, this was only released a little over a month ago.  Therefore we really need to document this requirement somewhere because most peoples TeX installation will need to be updated.
Sure, I'll gladly update the documentation to outline the new requirement. Do you have any pointers to the best place to do that?

Resolving patch:
diff --git a/qiskit/tools/visualization/_circuit_visualization.py b/qiskit/tools/visualization/_circuit_visualization.py
--- a/qiskit/tools/visualization/_circuit_visualization.py
+++ b/qiskit/tools/visualization/_circuit_visualization.py
@@ -261,6 +261,8 @@ def latex_circuit_drawer(circuit,
                          style=None):
     """Draw a quantum circuit based on latex (Qcircuit package)
 
+    Requires version >=2.6.0 of the qcircuit LaTeX package.
+
     Args:
         circuit (QuantumCircuit): a quantum circuit
         basis (str): comma separated list of gates


Test patch:
Repository: Qiskit/qiskit

Issue:
LaTeX Barriers are not centered between gates and measures on all columns
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

- **Qiskit Terra version**: latest master
- **Python version**: 3.7
- **Operating system**: linux

### What is the current behavior?

@nonhermitian example in issue #938 shows a circuit with a barrier being drawn with a measure after a gate but the barrier is not centered for the gate and measure on q0_15:

![image](https://user-images.githubusercontent.com/2447371/46037725-0b024580-c0d7-11e8-8dc6-f3d15fadb04f.png)

The barrier is being drawn from q0_0 (because the \barrier command in latex draws the barrier line down from the topmost bit) and the default horizontal offset is used because there is no measure immediately after the gate on that bit. This ends up being incorrect on q0_15 because because there is a measure immediately after the gate on that bit which moves the center line between those 2 boxes to the left.

### Steps to reproduce the problem

Draw a circuit with a measure right after a gate on a bit covered by the barrier, but is not the bit where \barrier will be written in the latex.

### What is the expected behavior?

The barrier line should centered between gates and measures on all bits covered by a barrier, not just the topmost bit (where the \barrier call is made from in the latex)

### Suggested solutions

We need to adjust the check in the latex circuit drawer that looks for a measure directly after a gate on a bit to check all bits being covered by the barrier, not just the bit 



Discussion:

Resolving patch:
diff --git a/qiskit/tools/visualization/_circuit_visualization.py b/qiskit/tools/visualization/_circuit_visualization.py
--- a/qiskit/tools/visualization/_circuit_visualization.py
+++ b/qiskit/tools/visualization/_circuit_visualization.py
@@ -1257,10 +1257,16 @@ def _build_latex_array(self, aliases=None):
 
                 try:
                     self._latex[pos_1][columns] = "\\meter"
-                    prev_entry = self._latex[pos_1][columns - 1]
-                    if 'barrier' in prev_entry:
-                        self._latex[pos_1][columns - 1] = prev_entry.replace(
-                            '\\barrier{', '\\barrier[-1.15em]{')
+                    prev_column = [x[columns - 1] for x in self._latex]
+                    for item, prev_entry in enumerate(prev_column):
+                        if 'barrier' in prev_entry:
+                            span = re.search('barrier{(.*)}', prev_entry)
+                            if span and (
+                                    item + int(span.group(1))) - pos_1 >= 0:
+                                self._latex[
+                                    item][columns - 1] = prev_entry.replace(
+                                        '\\barrier{', '\\barrier[-1.15em]{')
+
                     self._latex[pos_2][columns] = \
                         "\\cw \\cwx[-" + str(pos_2 - pos_1) + "]"
                 except Exception as e:


Test patch:
Repository: Qiskit/qiskit

Issue:
follow up from #948 add a  remove_all_accounts() command
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->

### What is the expected enhancement?
removed many accounts are annoying we need a remove_all command




Discussion:

Resolving patch:
diff --git a/qiskit/backends/ibmq/ibmqprovider.py b/qiskit/backends/ibmq/ibmqprovider.py
--- a/qiskit/backends/ibmq/ibmqprovider.py
+++ b/qiskit/backends/ibmq/ibmqprovider.py
@@ -149,6 +149,13 @@ def remove_account(self, token, url=QE_URL, **kwargs):
         if not removed:
             raise IBMQAccountError('Unable to find credentials')
 
+    def remove_accounts(self):
+        """Remove all accounts from this session and optionally from disk."""
+        current_creds = self._accounts.copy()
+        for creds in current_creds:
+            self.remove_account(current_creds[creds].credentials.token,
+                                current_creds[creds].credentials.url)
+
     def use_account(self, token, url=QE_URL, **kwargs):
         """Authenticate against IBMQ during this session.
 


Test patch:
diff --git a/test/python/test_registration.py b/test/python/test_registration.py
--- a/test/python/test_registration.py
+++ b/test/python/test_registration.py
@@ -134,6 +134,26 @@ def test_remove_account_from_disk(self):
             self.assertEqual(len(qiskit.IBMQ._accounts), 0)
             self.assertEqual(len(read_credentials_from_qiskitrc()), 0)
 
+    def test_remove_accounts(self):
+        """Test removing all accounts from session."""
+        with custom_qiskitrc(), mock_ibmq_provider():
+            qiskit.IBMQ.add_account('QISKITRC_TOKEN')
+            qiskit.IBMQ.add_account('QISKITRC_TOKEN',
+                                    url=IBMQ_TEMPLATE.format('a', 'b', 'c'))
+            qiskit.IBMQ.remove_accounts()
+            self.assertEqual(len(qiskit.IBMQ._accounts), 0)
+
+    def test_remove_accounts_from_disk(self):
+        """Test removing all account from disk."""
+        with custom_qiskitrc(), mock_ibmq_provider():
+            qiskit.IBMQ.add_account('QISKITRC_TOKEN')
+            qiskit.IBMQ.add_account('QISKITRC_TOKEN',
+                                    url=IBMQ_TEMPLATE.format('a', 'b', 'c'))
+            self.assertEqual(len(read_credentials_from_qiskitrc()), 2)
+            qiskit.IBMQ.remove_accounts()
+            self.assertEqual(len(qiskit.IBMQ._accounts), 0)
+            self.assertEqual(len(read_credentials_from_qiskitrc()), 0)
+
 
 # TODO: NamedTemporaryFiles do not support name in Windows
 @skipIf(os.name == 'nt', 'Test not supported in Windows')
Repository: Qiskit/qiskit

Issue:
Changing style in matplotlib circuit_drawer changes the circuit layout
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

- **Qiskit Terra version**: current master
- **Python version**: 3.7
- **Operating system**: OSX

### What is the current behavior?
The output from the Matplotlib circuit drawer changes when the `style` kwarg is modified

### Steps to reproduce the problem
`circuit_drawer(circ)` vs `circuit_drawer(circ,style=qx_color_scheme())`: (Here I show only the first pane of the circuit)

<img width="964" alt="screen shot 2018-09-25 at 5 44 48 am" src="https://user-images.githubusercontent.com/1249193/46006709-298c2080-c086-11e8-9c62-f05c5a91153e.png">

<img width="965" alt="screen shot 2018-09-25 at 5 45 33 am" src="https://user-images.githubusercontent.com/1249193/46006778-4de7fd00-c086-11e8-897d-433f48219b98.png">


### What is the expected behavior?
I would assume that the style does not change the circuit layout in the figure.


### Suggested solutions





Discussion:
Hi. @nkanazawa1989 and I will check the code.

Resolving patch:
diff --git a/qiskit/tools/visualization/_circuit_visualization.py b/qiskit/tools/visualization/_circuit_visualization.py
--- a/qiskit/tools/visualization/_circuit_visualization.py
+++ b/qiskit/tools/visualization/_circuit_visualization.py
@@ -32,7 +32,6 @@
     patches as patches, pyplot as plt
 
 from qiskit._qiskiterror import QISKitError
-from qiskit._quantumcircuit import QuantumCircuit
 from qiskit.wrapper import load_qasm_file
 from qiskit.dagcircuit import DAGCircuit
 from qiskit.tools.visualization._error import VisualizationError
@@ -243,7 +242,7 @@ def qx_color_scheme():
         "cregbundle": False,
         "plotbarrier": False,
         "showindex": False,
-        "compress": False,
+        "compress": True,
         "margin": [2.0, 0.0, 0.0, 0.3],
         "creglinestyle": "solid",
         "reversebits": False
@@ -1464,7 +1463,7 @@ def load_qasm_file(self, filename):
         circuit = load_qasm_file(filename, name='draw', basis_gates=self._basis)
         self.parse_circuit(circuit)
 
-    def parse_circuit(self, circuit: QuantumCircuit):
+    def parse_circuit(self, circuit):
         dag_circuit = DAGCircuit.fromQuantumCircuit(circuit, expand_gates=False)
         self._ast = transpile(dag_circuit, basis_gates=self._basis, format='json')
         self._registers()


Test patch:
Repository: Qiskit/qiskit

Issue:
Using simulator instructions crashes the latex drawer
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

- **Qiskit Terra version**: latest master
- **Python version**: 3.7
- **Operating system**: linux

### What is the current behavior?

Attempting to use the latex drawer to render a circuit with simulator instructions stack traces in the dagunroller. For example:

```
Traceback (most recent call last):
  File "test_qiskit.py", line 67, in <module>
    visualization.generate_latex_source(qc, filename='out.tex')
  File "/tmp/qiskit/qiskit-terra/qiskit/tools/visualization/_circuit_visualization.py", line 354, in generate_latex_source
    json_circuit = transpile(dag_circuit, basis_gates=basis, format='json')
  File "/tmp/qiskit/qiskit-terra/qiskit/transpiler/_transpiler.py", line 346, in transpile
    dag = dag_unroller.expand_gates()
  File "/tmp/qiskit/qiskit-terra/qiskit/unroll/_dagunroller.py", line 86, in expand_gates
    not self.dag_circuit.gates[current_node["name"]]["opaque"]:
KeyError: 'snapshot'
```
It looks like it's trying to treat the snapshot instruction as a gate (which it's not) and that's causing things to crash.

### Steps to reproduce the problem

I've been running:

```
import qiskit.extensions.simulator
from qiskit import *
from qiskit.tools import visualization

q = QuantumRegister(2)
c = ClassicalRegister(1)
qc = QuantumCircuit(q, c)

qc.x(q[0])
qc.snapshot(slot=3)
qc.x(q[1])
qc.h(q[0])
qc.barrier()
qc.measure(q[0], c[0])

visualization.generate_latex_source(qc, filename='out.tex')
```
Also replacing snapshot() with save(), load(), and noise()

### What is the expected behavior?

This should draw a circuit (the barriers won't be drawn for the simulator instructions, that's what I was working on adding when I encountered this) and not stack trace.

### Suggested solutions

Fix the crash.


Discussion:

Resolving patch:
diff --git a/qiskit/unroll/_dagunroller.py b/qiskit/unroll/_dagunroller.py
--- a/qiskit/unroll/_dagunroller.py
+++ b/qiskit/unroll/_dagunroller.py
@@ -78,11 +78,12 @@ def expand_gates(self, basis=None):
             gatedefs.append(Gate(children))
         # Walk through the DAG and examine each node
         builtins = ["U", "CX", "measure", "reset", "barrier"]
+        simulator_builtins = ['snapshot', 'save', 'load', 'noise']
         topological_sorted_list = list(nx.topological_sort(self.dag_circuit.multi_graph))
         for node in topological_sorted_list:
             current_node = self.dag_circuit.multi_graph.node[node]
             if current_node["type"] == "op" and \
-               current_node["name"] not in builtins + basis and \
+               current_node["name"] not in builtins + basis + simulator_builtins and \
                not self.dag_circuit.gates[current_node["name"]]["opaque"]:
                 subcircuit, wires = self._build_subcircuit(gatedefs,
                                                            basis,


Test patch:
Repository: Qiskit/qiskit

Issue:
_matches_coupling_map seems to check single qubit ops too and fails
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

- **Qiskit Terra version**: 0.6.0
- **Python version**: 3.6
- **Operating system**: macos

### What is the current behavior?

Using _matches_coupling_map breaks and returns false at first single qubit op as single qubits are not in the coupling map

### Steps to reproduce the problem

Run the function on a dag 

### What is the expected behavior?

Ignore single qubits ops

### Suggested solutions
Check no of qubits. Have fixed and pull request ready to go if ok. 👍 




Discussion:

Resolving patch:
diff --git a/qiskit/transpiler/_transpiler.py b/qiskit/transpiler/_transpiler.py
--- a/qiskit/transpiler/_transpiler.py
+++ b/qiskit/transpiler/_transpiler.py
@@ -457,9 +457,10 @@ def _matches_coupling_map(dag, coupling_map):
     for _, data in dag.multi_graph.nodes(data=True):
         if data['type'] == 'op':
             gate_map = [qr[1] for qr in data['qargs']]
-            if gate_map not in coupling_map:
-                match = False
-                break
+            if len(gate_map) > 1:
+                if gate_map not in coupling_map:
+                    match = False
+                    break
     return match
 
 


Test patch:
Repository: Qiskit/qiskit

Issue:
IBMQ Provider Documentation is unclear/incorrect
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

- **Qiskit Terra version**:0.6.1
- **Python version**:
- **Operating system**:

### What is the current behavior?
-  [enable_account documentation](https://qiskit.org/documentation/_autodoc/qiskit.backends.ibmq.ibmqprovider.html?highlight=enable_account#qiskit.backends.ibmq.ibmqprovider.IBMQProvider.enable_account) is unclear. 

```
Authenticate and use one IBMQ account during this session.

Login into Quantum Experience or IBMQ using the provided credentials, adding the account to the current session. The account is not stored in disk.
```
The first and second sentence can be interpreted as contradictory.

- [save_account](https://qiskit.org/documentation/_autodoc/qiskit.backends.ibmq.ibmqprovider.html?highlight=save_account#qiskit.backends.ibmq.ibmqprovider.IBMQProvider.save_account) does not authenticate but claims to. 

### Steps to reproduce the problem



### What is the expected behavior?
Clear, concise and correct descriptions of the methods. 


### Suggested solutions
See (#1053).




Discussion:

Resolving patch:
diff --git a/qiskit/backends/ibmq/ibmqprovider.py b/qiskit/backends/ibmq/ibmqprovider.py
--- a/qiskit/backends/ibmq/ibmqprovider.py
+++ b/qiskit/backends/ibmq/ibmqprovider.py
@@ -98,7 +98,7 @@ def aliased_backend_names():
             }
 
     def enable_account(self, token, url=QE_URL, **kwargs):
-        """Authenticate and use one IBMQ account during this session.
+        """Authenticate a new IBMQ account and add for use during this session.
 
         Login into Quantum Experience or IBMQ using the provided credentials,
         adding the account to the current session. The account is not stored
@@ -117,7 +117,7 @@ def enable_account(self, token, url=QE_URL, **kwargs):
         self._append_account(credentials)
 
     def save_account(self, token, url=QE_URL, **kwargs):
-        """Authenticate against IBMQ and save the account to disk for future use.
+        """Save the account to disk for future use.
 
         Login into Quantum Experience or IBMQ using the provided credentials,
         adding the account to the current session. The account is stored in


Test patch: