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

Issue:
circuit without gates cannot be drew on latex
### Information

- **Qiskit Terra version**: master
- **Python version**: 3.7
- **Operating system**: MacOS

### Steps to reproduce the problem
```python
from qiskit import *
qc = QuantumCircuit(2)
qc.draw('latex')
```
```
IndexError: list index out of range
```

### What is the expected behavior?

Same as other drawers:
```python 
qc.draw('text')
```
```
q_0: 
     
q_1: 
```

```python
qc.draw('mpl')
```
![image](https://user-images.githubusercontent.com/766693/92166787-36375880-ee07-11ea-95ad-fef23f88e2fc.png)




Discussion:
@1ucian0 Maybe I can help with this, would that be ok?
Sure! Thanks! 
Perfect, I'll start taking a look later today.
Thanks!
Fwiw, this used to work fine. It looks this was a regression introduced in: https://github.com/Qiskit/qiskit-terra/pull/4410

Resolving patch:
diff --git a/qiskit/visualization/latex.py b/qiskit/visualization/latex.py
--- a/qiskit/visualization/latex.py
+++ b/qiskit/visualization/latex.py
@@ -299,7 +299,8 @@ def _get_image_depth(self):
         columns = 2
 
         # add extra column if needed
-        if self.cregbundle and (self.ops[0][0].name == "measure" or self.ops[0][0].condition):
+        if self.cregbundle and (self.ops and self.ops[0] and
+                                (self.ops[0][0].name == "measure" or self.ops[0][0].condition)):
             columns += 1
 
         # all gates take up 1 column except from those with labels (ie cu1)
@@ -382,7 +383,8 @@ def _build_latex_array(self):
 
         column = 1
         # Leave a column to display number of classical registers if needed
-        if self.cregbundle and (self.ops[0][0].name == "measure" or self.ops[0][0].condition):
+        if self.cregbundle and (self.ops and self.ops[0] and
+                                (self.ops[0][0].name == "measure" or self.ops[0][0].condition)):
             column += 1
         for layer in self.ops:
             num_cols_used = 1


Test patch:
diff --git a/test/python/visualization/test_visualization.py b/test/python/visualization/test_visualization.py
--- a/test/python/visualization/test_visualization.py
+++ b/test/python/visualization/test_visualization.py
@@ -30,6 +30,17 @@
 class TestLatexSourceGenerator(QiskitTestCase):
     """Qiskit latex source generator tests."""
 
+    def test_empty_circuit(self):
+        """Test draw an empty circuit"""
+        filename = self._get_resource_path('test_tiny.tex')
+        qc = QuantumCircuit(1)
+        try:
+            circuit_drawer(qc, filename=filename, output='latex_source')
+            self.assertNotEqual(os.path.exists(filename), False)
+        finally:
+            if os.path.exists(filename):
+                os.remove(filename)
+
     def test_tiny_circuit(self):
         """Test draw tiny circuit."""
         filename = self._get_resource_path('test_tiny.tex')
Repository: Qiskit/qiskit

Issue:
Aqua build fails: `No module named 'qiskit.circuit.library.template_circuits'`
<!-- ⚠️ 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**: Latest sources after https://github.com/Qiskit/qiskit-terra/commit/1c89cc59c8ec45311748e3f4c37e843068155d51
- **Python version**: any
- **Operating system**: any

### What is the current behavior?
1. `from qiskit.circuit.library import NLocal` fails.

2. The aqua build fails:
```
Failed to import test module: test.optimization
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/unittest/loader.py", line 470, in _find_test_path
    package = self._get_module_from_name(name)
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/runner/work/qiskit-aqua/qiskit-aqua/test/__init__.py", line 15, in <module>
    from .base_test_case import QiskitBaseTestCase
  File "/home/runner/work/qiskit-aqua/qiskit-aqua/test/base_test_case.py", line 23, in <module>
    from qiskit.aqua import set_logging_level, QiskitLogDomains
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/site-packages/qiskit/__init__.py", line 41, in <module>
    import qiskit.extensions
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/site-packages/qiskit/extensions/__init__.py", line 47, in <module>
    from qiskit.circuit.library.standard_gates import *
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/site-packages/qiskit/circuit/library/__init__.py", line 245, in <module>
    from .template_circuits import *
ModuleNotFoundError: No module named 'qiskit.circuit.library.template_circuits'
```


### Steps to reproduce the problem
Logs from the aqua build: https://github.com/Qiskit/qiskit-aqua/runs/1100653018


### What is the expected behavior?
No errors.


### Suggested solutions
There's missing `qiskit/circuit/library/template_circuits/__init__.py`




Discussion:

Resolving patch:
diff --git a/qiskit/circuit/library/template_circuits/__init__.py b/qiskit/circuit/library/template_circuits/__init__.py
new file mode 100644
--- /dev/null
+++ b/qiskit/circuit/library/template_circuits/__init__.py
@@ -0,0 +1,11 @@
+# This code is part of Qiskit.
+#
+# (C) Copyright IBM 2017, 2020.
+#
+# This code is licensed under the Apache License, Version 2.0. You may
+# obtain a copy of this license in the LICENSE.txt file in the root directory
+# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
+#
+# Any modifications or derivative works of this code must retain this
+# copyright notice, and modified files need to carry a notice indicating
+# that they have been altered from the originals.


Test patch:
Repository: Qiskit/qiskit

Issue:
Super easy fix: backend_version should be backend_name, Result.__repr__
<!-- ⚠️ 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.16.0
- **Python version**: 3.8
- **Operating system**: Linux

### What is the current behavior?

When initializing a Result object with argument `(backend_name='backend_name', backend_version="0.0.0"...)` the repr prints backend_name as "0.0.0" (whatever the version is)

### Steps to reproduce the problem

Initialize a Result object with a backend_name and backend_version argument and print a __repr__

### What is the expected behavior?

Obviously they should be different

### Suggested solutions

In https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/result/result.py lines 62-68:
```
    def __repr__(self):
        out = ("Result(backend_name='%s', backend_version='%s', qobj_id='%s', "
               "job_id='%s', success=%s, results=%s" % (
                   self.backend_version,
                   self.backend_version, self.qobj_id, self.job_id, self.success,
                   self.results))
```

The first `self.backend_version` should be `self.backend_name`.



Discussion:
Can I try this? This will be my first issue

Resolving patch:
diff --git a/qiskit/result/result.py b/qiskit/result/result.py
--- a/qiskit/result/result.py
+++ b/qiskit/result/result.py
@@ -62,7 +62,7 @@ def __init__(self, backend_name, backend_version, qobj_id, job_id, success,
     def __repr__(self):
         out = ("Result(backend_name='%s', backend_version='%s', qobj_id='%s', "
                "job_id='%s', success=%s, results=%s" % (
-                   self.backend_version,
+                   self.backend_name,
                    self.backend_version, self.qobj_id, self.job_id, self.success,
                    self.results))
         if hasattr(self, 'date'):


Test patch:
diff --git a/test/python/result/test_result.py b/test/python/result/test_result.py
--- a/test/python/result/test_result.py
+++ b/test/python/result/test_result.py
@@ -77,7 +77,7 @@ def test_result_repr(self):
         exp_result = models.ExperimentResult(shots=14, success=True, meas_level=2,
                                              data=data, header=exp_result_header)
         result = Result(results=[exp_result], **self.base_result_args)
-        expected = ("Result(backend_name='1.0.0', backend_version='1.0.0', "
+        expected = ("Result(backend_name='test_backend', backend_version='1.0.0', "
                     "qobj_id='id-123', job_id='job-123', success=True, "
                     "results=[ExperimentResult(shots=14, success=True, "
                     "meas_level=2, data=ExperimentResultData(counts={'0x0': 4,"
Repository: Qiskit/qiskit

Issue:
ParametricPulse hash generates random numbers
<!-- ⚠️ 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**:
- **Python version**:
- **Operating system**:

### What is the current behavior?

```python
from qiskit import pulse

# cr90+
pulse1 = pulse.GaussianSquare(duration=688, amp=0.05031927020792325-0.0006260706605576848j, sigma=64, width=432)
# cr90-
pulse2 = pulse.GaussianSquare(duration=688, amp=-0.05031927020792325+0.000626070660557691j, sigma=64, width=432)

for _ in range(10):
    print(hash(pulse1), hash(pulse2))
```
returns
```
8742458569996 8742458569996
8742458569996 8742458569996
8742458569996 8742458569996
8742458569996 8742458569996
8742458569996 8742458569996
8742458569996 8742458569996
8742458569996 8742458569996
8742458569996 8742458569996
8742458569996 8742458569996
-9223363294396205790 -9223363294396205790
```

### Steps to reproduce the problem

See above

### What is the expected behavior?

Return unique value

### Suggested solutions

This bug is caused because it generates hash based on python generator. Generator should be converted into tuple before hash generation.



Discussion:

Resolving patch:
diff --git a/qiskit/pulse/library/parametric_pulses.py b/qiskit/pulse/library/parametric_pulses.py
--- a/qiskit/pulse/library/parametric_pulses.py
+++ b/qiskit/pulse/library/parametric_pulses.py
@@ -161,7 +161,7 @@ def __eq__(self, other: Pulse) -> bool:
         return super().__eq__(other) and self.parameters == other.parameters
 
     def __hash__(self) -> int:
-        return hash(self.parameters[k] for k in sorted(self.parameters))
+        return hash(tuple(self.parameters[k] for k in sorted(self.parameters)))
 
 
 class Gaussian(ParametricPulse):


Test patch:
diff --git a/test/python/pulse/test_pulse_lib.py b/test/python/pulse/test_pulse_lib.py
--- a/test/python/pulse/test_pulse_lib.py
+++ b/test/python/pulse/test_pulse_lib.py
@@ -223,6 +223,14 @@ def test_deprecated_parametric_pulses(self):
             self.assertEqual(const.get_waveform().samples[0], 0.1 + 0.4j)
             self.assertEqual(len(const.get_waveform().samples), 150)
 
+    def test_hash_generation(self):
+        """Test if pulse generate unique hash."""
+        test_hash = [hash(GaussianSquare(duration=688, amp=0.1+0.1j, sigma=64, width=432))
+                     for _ in range(10)]
+
+        ref_hash = [test_hash[0] for _ in range(10)]
+
+        self.assertListEqual(test_hash, ref_hash)
 
 # pylint: disable=invalid-name,unexpected-keyword-arg
Repository: Qiskit/qiskit

Issue:
Chipped figure in matplotlib for a plain quantum circuit
<!-- ⚠️ 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.16.1
- **Python version**: 3.8.6
- **Operating system**: Artix Linux

### What is the current behavior?
When drawing a plain quantum circuit (just initializing the quantum and classical registers without implementing any gates), the figure rendered in matplotlib renders chipped text. Testing this with a previous release of terra (I used 0.15.1), the text appears fine without any chipping whatsoever.



### Steps to reproduce the problem
```python
from qiskit import *

qr = QuantumRegister(2)
cr = ClassicalRegister(3)
qc = QuantumCircuit(qr,cr)

qc.draw('mpl')
```

*With current release (0.16.1)*:
![Figure_3](https://user-images.githubusercontent.com/59497618/99046039-32b70f00-25b8-11eb-8495-36356d9d4c4c.png)


*With a previous release (0.15.1)*:
![Figure_1](https://user-images.githubusercontent.com/59497618/99044833-66913500-25b6-11eb-928b-0f413c479210.png)

### What is the expected behavior?
The expected behaviour is to draw the circuit without any text chipping and draw the circuit as implemented in version 0.15.1.


Discussion:
I'm willing to work on this issue.
Assigning it to you in that case. Thanks.

Resolving patch:
diff --git a/qiskit/visualization/matplotlib.py b/qiskit/visualization/matplotlib.py
--- a/qiskit/visualization/matplotlib.py
+++ b/qiskit/visualization/matplotlib.py
@@ -1059,7 +1059,8 @@ def _draw_ops(self, verbose=False):
             self._xmax = self._fold + 1 + self._x_offset - 0.9
             self._ymax = (n_fold + 1) * (self._n_lines + 1) - 1
         else:
-            self._xmax = max_anc + 1 + self._x_offset - 0.9
+            x_incr = 0.4 if not self._ops else 0.9
+            self._xmax = max_anc + 1 + self._x_offset - x_incr
             self._ymax = self._n_lines
 
         # add horizontal lines


Test patch:
diff --git a/test/ipynb/mpl/references/no_op_circut.png b/test/ipynb/mpl/references/no_op_circut.png
new file mode 100644
Binary files /dev/null and b/test/ipynb/mpl/references/no_op_circut.png differ
diff --git a/test/ipynb/mpl/test_circuit_matplotlib_drawer.py b/test/ipynb/mpl/test_circuit_matplotlib_drawer.py
--- a/test/ipynb/mpl/test_circuit_matplotlib_drawer.py
+++ b/test/ipynb/mpl/test_circuit_matplotlib_drawer.py
@@ -84,6 +84,12 @@ def test_empty_circuit(self):
 
         self.circuit_drawer(circuit, filename='empty_circut.png')
 
+    def test_no_ops(self):
+        """Test circuit with no ops.
+        See https://github.com/Qiskit/qiskit-terra/issues/5393 """
+        circuit = QuantumCircuit(2, 3)
+        self.circuit_drawer(circuit, filename='no_op_circut.png')
+
     def test_long_name(self):
         """Test to see that long register names can be seen completely
         As reported in #2605
Repository: Qiskit/qiskit

Issue:
Import time regression after #5358
<!-- ⚠️ 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**: after 300e9507
- **Python version**: 3.6
- **Operating system**: Linux

### What is the current behavior?

After #5358 merged a significant import time performance was introduced:

https://qiskit.github.io/qiskit/#import.QiskitImport.time_qiskit_import?commits=300e9507

### Steps to reproduce the problem

Run `import qiskit`


Discussion:
Digging into this it's sympy again from `pulse.utils`:

![Screenshot_2021-01-04_07-58-50](https://user-images.githubusercontent.com/2447371/103537628-bc6db500-4e62-11eb-929f-bce4dd3d7a87.png)

I fixed this quite recently in #5416 we really need to stop using sympy.

Resolving patch:
diff --git a/qiskit/pulse/utils.py b/qiskit/pulse/utils.py
--- a/qiskit/pulse/utils.py
+++ b/qiskit/pulse/utils.py
@@ -15,7 +15,6 @@
 from typing import List, Dict, Union
 
 import numpy as np
-from sympy import srepr
 
 from qiskit.circuit.parameterexpression import ParameterExpression
 
@@ -56,6 +55,8 @@ def format_parameter_value(operand: Union[ParameterExpression]
     # however this error can be ignored in practice though we need to be careful for unittests.
     # i.e. "pi=3.141592653589793" will be evaluated as "3.14159265358979"
     # no DAC that recognizes the resolution of 1e-15 but they are AlmostEqual in tests.
+    from sympy import srepr
+
     math_expr = srepr(operand)
     try:
         # value is assigned


Test patch:
Repository: Qiskit/qiskit

Issue:
Quantum info Operator does not work with delay operations
<!-- ⚠️ 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**: latest
- **Python version**:
- **Operating system**:

### What is the current behavior?
Trying to convert a circuit with delays to `Operator` gives:

QiskitError: 'Cannot apply Instruction: delay'



### Steps to reproduce the problem



### What is the expected behavior?
Since delays do nothing with respect to the Unitary operator I would expect this to work.  


### Suggested solutions





Discussion:

Resolving patch:
diff --git a/qiskit/circuit/delay.py b/qiskit/circuit/delay.py
--- a/qiskit/circuit/delay.py
+++ b/qiskit/circuit/delay.py
@@ -59,6 +59,15 @@ def __array__(self, dtype=None):
         return np.array([[1, 0],
                          [0, 1]], dtype=dtype)
 
+    def to_matrix(self) -> np.ndarray:
+        """Return a Numpy.array for the unitary matrix. This has been
+        added to enable simulation without making delay a full Gate type.
+
+        Returns:
+            np.ndarray: matrix representation.
+        """
+        return self.__array__(dtype=complex)
+
     def __repr__(self):
         """Return the official string representing the delay."""
         return "%s(duration=%s[unit=%s])" % \


Test patch:
diff --git a/test/python/pulse/test_instructions.py b/test/python/pulse/test_instructions.py
--- a/test/python/pulse/test_instructions.py
+++ b/test/python/pulse/test_instructions.py
@@ -112,6 +112,19 @@ def test_delay(self):
         self.assertEqual(delay.duration, 10)
         self.assertIsInstance(delay.duration, np.integer)
 
+    def test_operator_delay(self):
+        """Test Operator(delay)."""
+        from qiskit.circuit import QuantumCircuit
+        from qiskit.quantum_info import Operator
+        circ = QuantumCircuit(1)
+        circ.delay(10)
+        op_delay = Operator(circ)
+
+        expected = QuantumCircuit(1)
+        expected.i(0)
+        op_identity = Operator(expected)
+        self.assertEqual(op_delay, op_identity)
+
 
 class TestSetFrequency(QiskitTestCase):
     """Set frequency tests."""
Repository: Qiskit/qiskit

Issue:
QuantumCircuit.remove_final_measurements leaves remnant classical bits?
<!-- ⚠️ 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.16.3
- **Python version**: 
- **Operating system**:

### What is the current behavior?
`QuantumCircuit.remove_final_measurements()` removes the idle classical registers - just as its docstring states - but not the associated classical bits.

### Steps to reproduce the problem

```python
from qiskit import QuantumCircuit

qc = QuantumCircuit(1,1)
qc.measure(0,0)
qc.remove_final_measurements()

assert len(qc.cregs)==0, "idle classical register not removed"
assert len(qc.clbits)==0, f"idle classical bits not removed: {qc.clbits}"
```

### What is the expected behavior?



### Suggested solutions
If the above behavior is not intended, `circ.clbits.clear()` before parsing the new circuit DAG for active classical bits?


Discussion:

Resolving patch:
diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py
--- a/qiskit/circuit/quantumcircuit.py
+++ b/qiskit/circuit/quantumcircuit.py
@@ -1748,6 +1748,8 @@ def remove_final_measurements(self, inplace=True):
             inst.condition = node.condition
             circ.append(inst, qubits, clbits)
 
+        circ.clbits.clear()
+
         if not inplace:
             return circ
         else:


Test patch:
diff --git a/test/python/circuit/test_circuit_operations.py b/test/python/circuit/test_circuit_operations.py
--- a/test/python/circuit/test_circuit_operations.py
+++ b/test/python/circuit/test_circuit_operations.py
@@ -363,6 +363,20 @@ def test_remove_final_measurements_multiple_measures(self):
 
         self.assertEqual(expected, circuit)
 
+    def test_remove_final_measurements_5802(self):
+        """Test remove_final_measurements removes classical bits
+        https://github.com/Qiskit/qiskit-terra/issues/5802.
+        """
+        qr = QuantumRegister(2)
+        cr = ClassicalRegister(2)
+
+        circuit = QuantumCircuit(qr, cr)
+        circuit.measure(qr, cr)
+        circuit.remove_final_measurements()
+
+        self.assertEqual(circuit.cregs, [])
+        self.assertEqual(circuit.clbits, [])
+
     def test_reverse(self):
         """Test reverse method reverses but does not invert."""
         qc = QuantumCircuit(2, 2)
Repository: Qiskit/qiskit

Issue:
duplicated code: Arrow3D classs
The class `Arrow3D` seems to be duplicated in `qiskit/visualization/state_visualization.py` and in `qiskit/visualization/bloch.py`. Maybe a faulty merge?


Discussion:
Lines 61-71 in `qiskit/visualization/bloch.py` and Lines 689-702 in `qiskit/visualization/state_visualization.py`, right?

They do seem to be duplicated, I assume it would be easier to write it once and import over. Would anyone happen to know which one is the 'correct' version? 
The only difference I can see is that `bloch.py` uses 
```py
x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.set_positions((x_s[0], y_s[0]), (x_s[1], y_s[1]))
```

Whereas `state_visualization.py` uses
```py
xs, ys, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
```


Resolving patch:
diff --git a/qiskit/visualization/state_visualization.py b/qiskit/visualization/state_visualization.py
--- a/qiskit/visualization/state_visualization.py
+++ b/qiskit/visualization/state_visualization.py
@@ -713,27 +713,11 @@ def plot_state_qsphere(
             "Must have Matplotlib installed. To install, run " '"pip install matplotlib".'
         )
 
-    from mpl_toolkits.mplot3d import proj3d
-    from matplotlib.patches import FancyArrowPatch
     import matplotlib.gridspec as gridspec
     from matplotlib import pyplot as plt
     from matplotlib.patches import Circle
     from matplotlib import get_backend
-
-    class Arrow3D(FancyArrowPatch):
-        """Standard 3D arrow."""
-
-        def __init__(self, xs, ys, zs, *args, **kwargs):
-            """Create arrow."""
-            FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)
-            self._verts3d = xs, ys, zs
-
-        def draw(self, renderer):
-            """Draw the arrow."""
-            xs3d, ys3d, zs3d = self._verts3d
-            xs, ys, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
-            self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
-            FancyArrowPatch.draw(self, renderer)
+    from qiskit.visualization.bloch import Arrow3D
 
     try:
         import seaborn as sns


Test patch: