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

Issue:
Allow inheritance of QuantumRegister and ClassicalRegister
Attempting to inherit from QuantumRegister or ClassicalRegister currently causes type errors in `instruction.py`'s constructor. There may be other areas that require updates to make this functionality viable.




Discussion:

Resolving patch:
diff --git a/qiskit/circuit/instruction.py b/qiskit/circuit/instruction.py
--- a/qiskit/circuit/instruction.py
+++ b/qiskit/circuit/instruction.py
@@ -47,9 +47,9 @@ def __init__(self, name, param, qargs, cargs, circuit=None):
         Raises:
             QiskitError: when the register is not in the correct format.
         """
-        if not all((type(i[0]), type(i[1])) == (QuantumRegister, int) for i in qargs):
+        if not all(isinstance(i[0], QuantumRegister) and isinstance(i[1], int) for i in qargs):
             raise QiskitError("qarg not (QuantumRegister, int) tuple")
-        if not all((type(i[0]), type(i[1])) == (ClassicalRegister, int) for i in cargs):
+        if not all(isinstance(i[0], ClassicalRegister) and isinstance(i[1], int) for i in cargs):
             raise QiskitError("carg not (ClassicalRegister, int) tuple")
         self.name = name
         self.param = []  # a list of gate params stored as sympy objects


Test patch:
Repository: Qiskit/qiskit

Issue:
Allow inheritance of QuantumRegister and ClassicalRegister
Attempting to inherit from QuantumRegister or ClassicalRegister currently causes type errors in `instruction.py`'s constructor. There may be other areas that require updates to make this functionality viable.




Discussion:

Resolving patch:
diff --git a/qiskit/circuit/instruction.py b/qiskit/circuit/instruction.py
--- a/qiskit/circuit/instruction.py
+++ b/qiskit/circuit/instruction.py
@@ -48,9 +48,9 @@ def __init__(self, name, params, qargs, cargs, circuit=None):
         Raises:
             QiskitError: when the register is not in the correct format.
         """
-        if not all((type(i[0]), type(i[1])) == (QuantumRegister, int) for i in qargs):
+        if not all(isinstance(i[0], QuantumRegister) and isinstance(i[1], int) for i in qargs):
             raise QiskitError("qarg not (QuantumRegister, int) tuple")
-        if not all((type(i[0]), type(i[1])) == (ClassicalRegister, int) for i in cargs):
+        if not all(isinstance(i[0], ClassicalRegister) and isinstance(i[1], int) for i in cargs):
             raise QiskitError("carg not (ClassicalRegister, int) tuple")
         self.name = name
         self.params = []  # a list of gate params stored


Test patch:
Repository: Qiskit/qiskit

Issue:
rzz gate
<!-- ⚠️ 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.7.2
- **Python version**: 3.6.6
- **Operating system**: Windows 10

### What is the current behavior?

rzz gate appears to give incorrect results

### Steps to reproduce the problem

rzz gate rule defined in https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/extensions/standard/rzz.py

```
            CnotGate(q[0], q[1]),
            U1Gate(self.params[0], q[0]),
            CnotGate(q[0], q[1])
```

### What is the expected behavior?

I think it should be
```
            CnotGate(q[0], q[1]),
            U1Gate(self.params[0], q[1]),
            CnotGate(q[0], q[1])
```
the u1 phase should be on the target instead of control

### Suggested solutions

modify rzz gate definition to give the right behavior.



Discussion:

Resolving patch:
diff --git a/qiskit/extensions/standard/rzz.py b/qiskit/extensions/standard/rzz.py
--- a/qiskit/extensions/standard/rzz.py
+++ b/qiskit/extensions/standard/rzz.py
@@ -34,7 +34,7 @@ def _define_decompositions(self):
         decomposition.add_qreg(q)
         rule = [
             CnotGate(q[0], q[1]),
-            U1Gate(self.params[0], q[0]),
+            U1Gate(self.params[0], q[1]),
             CnotGate(q[0], q[1])
         ]
         for inst in rule:


Test patch:
Repository: Qiskit/qiskit

Issue:
Custom gates are not extending circuit.definitions
This is some sort of follow up from #875.

It seems that, at some point, we broke `circuit.definitions`:
```
>>> from qiskit import QuantumCircuit 
>>> qasm_string = """OPENQASM 2.0; 
>>> gate id a { U(0,0,0) a; } 
>>> """ 
>>> circuit = QuantumCircuit.from_qasm_str(qasm_string) 
>>> circuit.definitions.keys()                                                                                                                                                                   
odict_keys([])
```


Discussion:
I think this is due to #1781 as this removed the gate definitions from the DAG, so when the AST is converted into a DAG the information about gate definitions is lost as it is no longer copied across.

A simple solution would be to create a `definitions` variable on DAGCircuit which is the same as `AstInterpreter.gates` and `QuantumCircuit.definitions`, but this rather defeats the point of #1781.
Thanks for hunting it down. Was that the intention @ajavadia ?

Resolving patch:
diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py
--- a/qiskit/circuit/quantumcircuit.py
+++ b/qiskit/circuit/quantumcircuit.py
@@ -8,7 +8,6 @@
 """
 Quantum circuit object.
 """
-from collections import OrderedDict
 from copy import deepcopy
 import itertools
 import sys
@@ -30,18 +29,6 @@ class QuantumCircuit:
     header = "OPENQASM 2.0;"
     extension_lib = "include \"qelib1.inc\";"
 
-    # Class variable with gate definitions
-    # This is a dict whose values are dicts with the
-    # following keys:
-    #   "print" = True or False
-    #   "opaque" = True or False
-    #   "n_args" = number of real parameters
-    #   "n_bits" = number of qubits
-    #   "args"   = list of parameter names
-    #   "bits"   = list of qubit names
-    #   "body"   = GateBody AST node
-    definitions = OrderedDict()
-
     def __init__(self, *regs, name=None):
         """Create a new circuit.
 
@@ -264,22 +251,6 @@ def _check_compatible_regs(self, rhs):
                     if element1 != element2:
                         raise QiskitError("circuits are not compatible")
 
-    def _gate_string(self, name):
-        """Return a QASM string for the named gate."""
-        out = ""
-        if self.definitions[name]["opaque"]:
-            out = "opaque " + name
-        else:
-            out = "gate " + name
-        if self.definitions[name]["n_args"] > 0:
-            out += "(" + ",".join(self.definitions[name]["args"]) + ")"
-        out += " " + ",".join(self.definitions[name]["bits"])
-        if self.definitions[name]["opaque"]:
-            out += ";"
-        else:
-            out += "\n{\n" + self.definitions[name]["body"].qasm() + "}\n"
-        return out
-
     def qasm(self):
         """Return OPENQASM string."""
         string_temp = self.header + "\n"


Test patch:
Repository: Qiskit/qiskit

Issue:
missing qiskit/qobj/models/__init__.py
<!-- ⚠️ 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?
`qiskit.qobj.models` package is not created in wheel file.

### Steps to reproduce the problem



### What is the expected behavior?
`qiskit/qobj/models` is created.


### Suggested solutions
add `qiskit/qobj/models/__init__.py` appropriately.




Discussion:

Resolving patch:
diff --git a/qiskit/qobj/models/__init__.py b/qiskit/qobj/models/__init__.py
new file mode 100644
--- /dev/null
+++ b/qiskit/qobj/models/__init__.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2018, IBM.
+#
+# This source code is licensed under the Apache License, Version 2.0 found in
+# the LICENSE.txt file in the root directory of this source tree.
+
+"""Models for the Qobj."""


Test patch:
Repository: Qiskit/qiskit

Issue:
lint error is left in PR
<!-- ⚠️ 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?
lint error is left in #2027 


### Steps to reproduce the problem



### What is the expected behavior?
remove lint error


### Suggested solutions
optimize import order in `qiskit.qobj.models.pulse` and `qiskit.qobj.models.qasm`



Discussion:

Resolving patch:
diff --git a/qiskit/qobj/models/__init__.py b/qiskit/qobj/models/__init__.py
--- a/qiskit/qobj/models/__init__.py
+++ b/qiskit/qobj/models/__init__.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Copyright 2018, IBM.
+# Copyright 2019, IBM.
 #
 # This source code is licensed under the Apache License, Version 2.0 found in
 # the LICENSE.txt file in the root directory of this source tree.
diff --git a/qiskit/qobj/models/pulse.py b/qiskit/qobj/models/pulse.py
--- a/qiskit/qobj/models/pulse.py
+++ b/qiskit/qobj/models/pulse.py
@@ -9,13 +9,13 @@
 
 from marshmallow.validate import Range, Regexp, Length, OneOf
 
-from .base import (QobjInstructionSchema, QobjExperimentConfigSchema, QobjExperimentSchema,
-                   QobjConfigSchema, QobjInstruction, QobjExperimentConfig,
-                   QobjExperiment, QobjConfig)
 from qiskit.qobj.utils import MeasReturnType
 from qiskit.validation import bind_schema, BaseSchema, BaseModel
 from qiskit.validation.fields import (Integer, String, Number, Complex,
                                       List, Nested, MeasurementParameter)
+from .base import (QobjInstructionSchema, QobjExperimentConfigSchema, QobjExperimentSchema,
+                   QobjConfigSchema, QobjInstruction, QobjExperimentConfig,
+                   QobjExperiment, QobjConfig)
 
 
 class QobjMeasurementOptionSchema(BaseSchema):
diff --git a/qiskit/qobj/models/qasm.py b/qiskit/qobj/models/qasm.py
--- a/qiskit/qobj/models/qasm.py
+++ b/qiskit/qobj/models/qasm.py
@@ -9,11 +9,11 @@
 
 from marshmallow.validate import Range, Length, Regexp
 
+from qiskit.validation import bind_schema, BaseSchema, BaseModel
+from qiskit.validation.fields import List, Integer, InstructionParameter, Nested, String
 from .base import (QobjInstructionSchema, QobjExperimentConfigSchema, QobjExperimentSchema,
                    QobjConfigSchema, QobjInstruction, QobjExperimentConfig,
                    QobjExperiment, QobjConfig)
-from qiskit.validation import bind_schema, BaseSchema, BaseModel
-from qiskit.validation.fields import List, Integer, InstructionParameter, Nested, String
 
 
 class QobjConditionalSchema(BaseSchema):


Test patch:
Repository: Qiskit/qiskit

Issue:
mpl drawer modifies instruction params
<!-- ⚠️ 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
import numpy as np
from qiskit.circuit import QuantumCircuit, QuantumRegister
from qiskit.quantum_info.random import random_unitary

q = QuantumRegister(2)
qv = QuantumCircuit(q)
U = random_unitary(4)
qv.append(U, [q[0], q[1]])

print(qv.data[0][0].params)
qv.draw(output='mpl')
print(qv.data[0][0].params)
```

Before the drawer, it is a numpy array, after, it becomes a string.




Discussion:

Resolving patch:
diff --git a/qiskit/visualization/matplotlib.py b/qiskit/visualization/matplotlib.py
--- a/qiskit/visualization/matplotlib.py
+++ b/qiskit/visualization/matplotlib.py
@@ -785,21 +785,26 @@ def _draw_ops(self, verbose=False):
 
     @staticmethod
     def param_parse(v, pimode=False):
+
+        # create an empty list to store the parameters in
+        param_parts = [None] * len(v)
         for i, e in enumerate(v):
+
             if pimode:
                 try:
-                    v[i] = MatplotlibDrawer.format_pi(e)
+                    param_parts[i] = MatplotlibDrawer.format_pi(e)
                 except TypeError:
-                    v[i] = str(e)
+                    param_parts[i] = str(e)
             else:
                 try:
-                    v[i] = MatplotlibDrawer.format_numeric(e)
+                    param_parts[i] = MatplotlibDrawer.format_numeric(e)
                 except TypeError:
-                    v[i] = str(e)
-            if v[i].startswith('-'):
-                v[i] = '$-$' + v[i][1:]
-        param = ', '.join(v)
-        return param
+                    param_parts[i] = str(e)
+            if param_parts[i].startswith('-'):
+                param_parts[i] = '$-$' + param_parts[i][1:]
+
+        param_parts = ', '.join(param_parts)
+        return param_parts
 
     @staticmethod
     def format_pi(val):


Test patch:
Repository: Qiskit/qiskit

Issue:
mpl drawer: unitary gate looks messy for 1 qubit
<!-- ⚠️ 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?
If I add unitary gates to the circuit, they show up fine in the `mpl` drawer except for the 1-qubit case. The single-qubit case should also not print the full matrix, and just do a box labeled "unitary".

```python
from qiskit import QuantumRegister, QuantumCircuit
from qiskit.quantum_info.random import random_unitary
qr = QuantumRegister(4)
qc = QuantumCircuit(qr)
U1 = random_unitary(2)
U2 = random_unitary(4)
U3 = random_unitary(8)
U4 = random_unitary(16)
qc.append(U1, [qr[0]])
qc.append(U2, [qr[0], qr[1]])
qc.append(U3, [qr[0], qr[1], qr[2]])
qc.append(U4, [qr[0], qr[1], qr[2], qr[3]])
qc.draw(output='mpl')
```
![image](https://user-images.githubusercontent.com/8622381/56902007-64fd2c00-6a67-11e9-81f5-79c985cb4dab.png)



Discussion:
It looks like the box isn't in the correct place for the 4-qubit case? Potentially a separate issue
It's a bit of an offset, probably due to that 0 label at the top. Not a big deal but yes would be nice to fix that too.
> It looks like the box isn't in the correct place for the 4-qubit case? Potentially a separate issue

Yeah, they look like 2 separate issues. It looks like the dynamic sizing for the 4 qubit case could be off slightly. (although my eyes may be playing ticks on me as I think I see the spacing between qubit 0 and 1 as slightly larger) The label issue is probably caused by the param fix in #2169 treating the matrix as a string parameter. We'll probably just need to add real type checking there.

Resolving patch:
diff --git a/qiskit/visualization/matplotlib.py b/qiskit/visualization/matplotlib.py
--- a/qiskit/visualization/matplotlib.py
+++ b/qiskit/visualization/matplotlib.py
@@ -658,8 +658,12 @@ def _draw_ops(self, verbose=False):
                 elif len(q_xy) == 1:
                     disp = op.name
                     if param:
-                        self._gate(q_xy[0], wide=_iswide, text=disp,
-                                   subtext='{}'.format(param))
+                        prm = '{}'.format(param)
+                        if len(prm) < 20:
+                            self._gate(q_xy[0], wide=_iswide, text=disp,
+                                       subtext=prm)
+                        else:
+                            self._gate(q_xy[0], wide=_iswide, text=disp)
                     else:
                         self._gate(q_xy[0], wide=_iswide, text=disp)
                 #


Test patch:
Repository: Qiskit/qiskit

Issue:
qiskit._util deprecation warning on `import qiskit`

```
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:30:03)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import qiskit
/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/_util.py:18: DeprecationWarning: The qiskit._util module is deprecated and has been renamed qiskit.util. Please update your imports as qiskit._util will beremoved in Qiskit Terra 0.9.
  'removed in Qiskit Terra 0.9.', DeprecationWarning)
```


Discussion:
Hmm, we'll have to change how we emit the deprecation warning for that. I just threw it in the bare module to only raise it on import and was simple. I guess we'll have to make a passthrough function that gets called on module getattr that calls qiskit.util() and emits the deprecation warning only from there

Resolving patch:
diff --git a/qiskit/_util.py b/qiskit/_util.py
--- a/qiskit/_util.py
+++ b/qiskit/_util.py
@@ -16,10 +16,8 @@
 
 """Compat shim for backwards compatability with qiskit.util."""
 
-import warnings
+# The 'qiskit._util' module is deprecated and has been renamed
+# 'qiskit.util'. Please update your imports as 'qiskit._util'
+# will be removed in Qiskit Terra 0.9.
 
 from qiskit.util import *
-
-warnings.warn('The qiskit._util module is deprecated and has been renamed '
-              'qiskit.util. Please update your imports as qiskit._util will be'
-              'removed in Qiskit Terra 0.9.', DeprecationWarning)


Test patch:
Repository: Qiskit/qiskit

Issue:
transpile not available from import *
<!-- ⚠️ 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**: master
- **Python version**:
- **Operating system**:

### What is the current behavior?
The `transpile` function is still not available using `from qiskit import *`.  The previous issue #2178 was closed assuming that this was fixed, but it is not.


### Steps to reproduce the problem



### What is the expected behavior?



### Suggested solutions





Discussion:

Resolving patch:
diff --git a/qiskit/__init__.py b/qiskit/__init__.py
--- a/qiskit/__init__.py
+++ b/qiskit/__init__.py
@@ -30,6 +30,7 @@
 from qiskit.circuit import QuantumRegister
 from qiskit.circuit import QuantumCircuit
 from qiskit.execute import execute
+from qiskit.compiler import transpile, assemble
 
 # The qiskit.extensions.x imports needs to be placed here due to the
 # mechanism for adding gates dynamically.


Test patch:
Repository: Qiskit/qiskit

Issue:
disassemble_circuits() suggested in qobj_to_circuits.py DeprecationWarning doesn't exist
<!-- ⚠️ 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.8.0
- **Python version**: 3.7.2
- **Operating system**: macOS

`qobj_to_circuits` gives the following `DeprecationWarning`:

```python
.../qiskit/converters/qobj_to_circuits.py:34: DeprecationWarning: qiskit.converters.qobj_to_circuit() is deprecated and will be removed in Qiskit Terra 0.9. Please use qiskit.compiler.disassemble_circuits() to convert a qobj to list of circuits.
```

but `qiskit.compiler.disassemble_circuits()` doesn't exist.

### What is the current behavior?
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'disassemble_circuits' from 'qiskit.compiler' (/Users/matteo/Work/projects/ibmq/env/lib/python3.7/site-packages/qiskit/compiler/__init__.py)
```

### Steps to reproduce the problem
1. Installed qiskit in a new python virtualenv with `pip install qiskit`
2.  `from qiskit.compiler import disassemble_circuits`

```
>>> qiskit.__qiskit_version__
{'qiskit': '0.10.0', 'qiskit-terra': '0.8.0', 'qiskit-ignis': '0.1.1', 'qiskit-aer': '0.2.0', 'qiskit-ibmq-provider': '0.2.1', 'qiskit-aqua': '0.5.0'}
```

### What is the expected behavior?
If a function is deprecated, and the warning suggests to use a new function, this function should exist in the current release.

### Suggested solutions

Implement the function or change the deprecation warning.


Discussion:
Sorry there seems to be a mistake in the deprecation message. For now please use
```from qiskit.assembler import disassemble```

@mtreinish I think `disassemble` should be added under the `qiskit.compile` namespace.
yeah this is a bug we did not update the disassemble warning when we changed API. This was probably my fault. 
It was when I originally added the function (and deprecation message) in #2137 but it looks like that was changed in #2244 right before the release without updating the deprecation message.
so yeah my fault :-(

Resolving patch:
diff --git a/qiskit/converters/qobj_to_circuits.py b/qiskit/converters/qobj_to_circuits.py
--- a/qiskit/converters/qobj_to_circuits.py
+++ b/qiskit/converters/qobj_to_circuits.py
@@ -30,7 +30,7 @@ def qobj_to_circuits(qobj):
     """
     warnings.warn('qiskit.converters.qobj_to_circuit() is deprecated and will '
                   'be removed in Qiskit Terra 0.9. Please use '
-                  'qiskit.compiler.disassemble_circuits() to convert a qobj '
+                  'qiskit.assembler.disassemble() to convert a qobj '
                   'to list of circuits.', DeprecationWarning)
 
     variables = disassemble(qobj)


Test patch:
Repository: Qiskit/qiskit

Issue:
`assemble_schedules` breaks with default arguments
<!-- ⚠️ 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**: master
- **Python version**: 3.6.8
- **Operating system**: MacOS 10.14

### What is the current behavior?

The `assemble_schedules` function uses the kwarg `run_config=None` by default, which breaks the function when trying to construct a dictionary from `None`.

### Steps to reproduce the problem

```
from qiskit import IBMQ
from qiskit.compiler import assemble
from qiskit.assembler import assemble_schedules
from qiskit.pulse import functional_pulse
from qiskit import pulse

IBMQ.load_accounts()
backend_name = 'ibmq_poughkeepsie'
backend = IBMQ.get_backend(backend_name)

device = pulse.DeviceSpecification.create_from(backend)

@functional_pulse
def simple_square_pulse(duration):
    return [1/10] * duration

rabi_pulse = simple_square_pulse(duration=30)

schedule = pulse.Schedule(name='Simple square pulse')

schedule.insert(0, rabi_pulse(device.q[0].drive))

assemble_schedules([schedule])
```

### What is the expected behavior?

A valid qobj should be returned.

### Suggested solutions

The arg `run_config` should not be optional.


Discussion:

Resolving patch:
diff --git a/qiskit/assembler/assemble_schedules.py b/qiskit/assembler/assemble_schedules.py
--- a/qiskit/assembler/assemble_schedules.py
+++ b/qiskit/assembler/assemble_schedules.py
@@ -25,7 +25,7 @@
 logger = logging.getLogger(__name__)
 
 
-def assemble_schedules(schedules, qobj_id=None, qobj_header=None, run_config=None):
+def assemble_schedules(schedules, qobj_id, qobj_header, run_config):
     """Assembles a list of schedules into a qobj which can be run on the backend.
     Args:
         schedules (list[Schedule]): schedules to assemble


Test patch: