Repository: Qiskit/qiskit

Issue:
assemble for schedules ignores parametric_pulses argument
<!-- ⚠️ 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.18.1
- **Python version**: 3.8
- **Operating system**: N/A

### What is the current behavior?
The Qobj assembly ignores the `parametric_pulses` argument in `assemble` and instead always grabs the value from `backend.configuration().parametric_pulses`


### Steps to reproduce the problem
Run
```python
import numpy as np

# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile, Aer, IBMQ
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
from qiskit.providers.aer import QasmSimulator

# Loading your IBM Quantum account(s)
provider = IBMQ.load_account()

import qiskit
from qiskit import pulse, transpile, schedule, assemble

backend_sim = qiskit.providers.aer.PulseSimulator()

backend = provider.get_backend("ibmq_armonk")

sim = qiskit.providers.aer.PulseSimulator.from_backend(backend)

qc = QuantumCircuit(1, 1)
qc.x(0)
qc.measure(0, 0)

with pulse.build(backend, name='x') as x_q0:
    pulse.play(pulse.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0)) 

qc.add_calibration('x', (0,), x_q0)

sched = schedule(transpile(qc, backend), backend)
print(assemble(sched, backend))
```
Output:
```
Pulse Qobj: b7e66652-b7d1-496d-88cf-909645cef07c:
Config: {'init_qubits': True,
 'meas_level': 2,
 'meas_lo_freq': [6.993370669],
 'meas_return': 'avg',
 'memory': False,
 'memory_slot_size': 100,
 'memory_slots': 1,
 'n_qubits': 1,
 'parametric_pulses': ['gaussian', 'gaussian_square', 'drag', 'constant'],
 'pulse_library': [],
 'qubit_lo_freq': [4.971671601995368],
 'rep_time': 1000,
 'shots': 1024}
Header: {'backend_name': 'ibmq_armonk', 'backend_version': '2.4.14'}
Experiments:

Pulse Experiment:
Header:
{'memory_slots': 1, 'metadata': {}, 'name': 'circuit-121'}
Config:
{}

	Instruction: parametric_pulse
		t0: 0
		ch: d0
		pulse_shape: gaussian
		parameters: {'duration': 128, 'amp': (0.1+0j), 'sigma': 16}

	Instruction: parametric_pulse
		t0: 128
		ch: m0
		pulse_shape: gaussian_square
		parameters: {'duration': 22400, 'amp': (-0.3465902422523164+0.048736064423388015j), 'sigma': 64, 'width': 22144}

	Instruction: acquire
		t0: 128
		duration: 22400
		qubits: [0]
		memory_slot: [0]
```


### What is the expected behavior?
If `parametric_pulses = []` as forced by setting on the backend in the snippet below the corresponding output should be found.
```python
import numpy as np

# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile, Aer, IBMQ
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
from qiskit.providers.aer import QasmSimulator

# Loading your IBM Quantum account(s)
provider = IBMQ.load_account()

import qiskit
from qiskit import pulse, transpile, schedule, assemble

backend_sim = qiskit.providers.aer.PulseSimulator()

backend = provider.get_backend("ibmq_armonk")
backend.configuration().parametric_pulses = []
sim = qiskit.providers.aer.PulseSimulator.from_backend(backend)

qc = QuantumCircuit(1, 1)
qc.x(0)
qc.measure(0, 0)

with pulse.build(backend, name='x') as x_q0:
    pulse.play(pulse.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0)) 

qc.add_calibration('x', (0,), x_q0)

sched = schedule(transpile(qc, backend), backend)
print(assemble(sched, backend))
```
Output:
```
Pulse Qobj: 814a8513-b521-4f22-bcaf-bd51cc0daddf:
Config: {'init_qubits': True,
 'meas_level': 2,
 'meas_lo_freq': [6.993370669],
 'meas_return': 'avg',
 'memory': False,
 'memory_slot_size': 100,
 'memory_slots': 1,
 'n_qubits': 1,
 'parametric_pulses': [],
 'pulse_library': [{'name': '31c5b1f1b9535cf00b9799bbe468627002a33aa3eb70501d2b1dd47aee09d1e8',
                    'samples': array([1.19225697e-05+0.j, 2.25264953e-05+0.j, 3.58467417e-05+0.j,
       5.25095783e-05+0.j, 7.32669793e-05+0.j, 9.90171697e-05+0.j,
       1.30827430e-04+0.j, 1.69959153e-04+0.j, 2.17895079e-04+0.j,
       2.76368545e-04+0.j, 3.47394497e-04+0.j, 4.33301864e-04+0.j,
       5.36766803e-04+0.j, 6.60846138e-04+0.j, 8.09010169e-04+0.j,
       9.85173881e-04+0.j, 1.19372537e-03+0.j, 1.43955016e-03+0.j,
       1.72804995e-03+0.j, 2.06515413e-03+0.j, 2.45732229e-03+0.j,
       2.91153599e-03+0.j, 3.43527784e-03+0.j, 4.03649608e-03+0.j,
       4.72355291e-03+0.j, 5.50515509e-03+0.j, 6.39026522e-03+0.j,
       7.38799307e-03+0.j, 8.50746605e-03+0.j, 9.75767900e-03+0.j,
       1.11473237e-02+0.j, 1.26845996e-02+0.j, 1.43770072e-02+0.j,
       1.62311273e-02+0.j, 1.82523897e-02+0.j, 2.04448351e-02+0.j,
       2.28108763e-02+0.j, 2.53510626e-02+0.j, 2.80638564e-02+0.j,
       3.09454264e-02+0.j, 3.39894654e-02+0.j, 3.71870402e-02+0.j,
       4.05264794e-02+0.j, 4.39933069e-02+0.j, 4.75702260e-02+0.j,
       5.12371589e-02+0.j, 5.49713473e-02+0.j, 5.87475132e-02+0.j,
       6.25380844e-02+0.j, 6.63134807e-02+0.j, 7.00424605e-02+0.j,
       7.36925217e-02+0.j, 7.72303513e-02+0.j, 8.06223161e-02+0.j,
       8.38349830e-02+0.j, 8.68356608e-02+0.j, 8.95929485e-02+0.j,
       9.20772795e-02+0.j, 9.42614478e-02+0.j, 9.61211027e-02+0.j,
       9.76352005e-02+0.j, 9.87864008e-02+0.j, 9.95613967e-02+0.j,
       9.99511711e-02+0.j, 9.99511711e-02+0.j, 9.95613967e-02+0.j,
       9.87864008e-02+0.j, 9.76352005e-02+0.j, 9.61211027e-02+0.j,
       9.42614478e-02+0.j, 9.20772795e-02+0.j, 8.95929485e-02+0.j,
       8.68356608e-02+0.j, 8.38349830e-02+0.j, 8.06223161e-02+0.j,
       7.72303513e-02+0.j, 7.36925217e-02+0.j, 7.00424605e-02+0.j,
       6.63134807e-02+0.j, 6.25380844e-02+0.j, 5.87475132e-02+0.j,
       5.49713473e-02+0.j, 5.12371589e-02+0.j, 4.75702260e-02+0.j,
       4.39933069e-02+0.j, 4.05264794e-02+0.j, 3.71870402e-02+0.j,
       3.39894654e-02+0.j, 3.09454264e-02+0.j, 2.80638564e-02+0.j,
       2.53510626e-02+0.j, 2.28108763e-02+0.j, 2.04448351e-02+0.j,
       1.82523897e-02+0.j, 1.62311273e-02+0.j, 1.43770072e-02+0.j,
       1.26845996e-02+0.j, 1.11473237e-02+0.j, 9.75767900e-03+0.j,
       8.50746605e-03+0.j, 7.38799307e-03+0.j, 6.39026522e-03+0.j,
       5.50515509e-03+0.j, 4.72355291e-03+0.j, 4.03649608e-03+0.j,
       3.43527784e-03+0.j, 2.91153599e-03+0.j, 2.45732229e-03+0.j,
       2.06515413e-03+0.j, 1.72804995e-03+0.j, 1.43955016e-03+0.j,
       1.19372537e-03+0.j, 9.85173881e-04+0.j, 8.09010169e-04+0.j,
       6.60846138e-04+0.j, 5.36766803e-04+0.j, 4.33301864e-04+0.j,
       3.47394497e-04+0.j, 2.76368545e-04+0.j, 2.17895079e-04+0.j,
       1.69959153e-04+0.j, 1.30827430e-04+0.j, 9.90171697e-05+0.j,
       7.32669793e-05+0.j, 5.25095783e-05+0.j, 3.58467417e-05+0.j,
       2.25264953e-05+0.j, 1.19225697e-05+0.j])},
                   {'name': '76fa66618cd11e7d7522a3eda5128959b50ec346117ce7a6ef9587146ae56101',
                    'samples': array([-0.00251587+0.00035377j, -0.00424271+0.00059659j,
       -0.00600968+0.00084506j, ..., -0.00600968+0.00084506j,
       -0.00424271+0.00059659j, -0.00251587+0.00035377j])}],
 'qubit_lo_freq': [4.971671601995368],
 'rep_time': 1000,
 'shots': 1024}
Header: {'backend_name': 'ibmq_armonk', 'backend_version': '2.4.14'}
Experiments:

Pulse Experiment:
Header:
{'memory_slots': 1, 'metadata': {}, 'name': 'circuit-125'}
Config:
{}

	Instruction: 31c5b1f1b9535cf00b9799bbe468627002a33aa3eb70501d2b1dd47aee09d1e8
		t0: 0
		ch: d0

	Instruction: 76fa66618cd11e7d7522a3eda5128959b50ec346117ce7a6ef9587146ae56101
		t0: 128
		ch: m0

	Instruction: acquire
		t0: 128
		duration: 22400
		qubits: [0]
		memory_slot: [0]
```

### Suggested solutions
Update `assemble` to use the argument `parametric_pulses` and add a unittest for this case.




Discussion:

Resolving patch:
diff --git a/qiskit/compiler/assembler.py b/qiskit/compiler/assembler.py
--- a/qiskit/compiler/assembler.py
+++ b/qiskit/compiler/assembler.py
@@ -441,8 +441,8 @@ def _parse_pulse_args(
         if isinstance(rep_time, list):
             rep_time = rep_time[0]
         rep_time = int(rep_time * 1e6)  # convert sec to μs
-
-    parametric_pulses = parametric_pulses or getattr(backend_config, "parametric_pulses", [])
+    if parametric_pulses is None:
+        parametric_pulses = getattr(backend_config, "parametric_pulses", [])
 
     # create run configuration and populate
     run_config_dict = dict(


Test patch:
diff --git a/test/python/compiler/test_assembler.py b/test/python/compiler/test_assembler.py
--- a/test/python/compiler/test_assembler.py
+++ b/test/python/compiler/test_assembler.py
@@ -1355,6 +1355,36 @@ def test_assemble_parametric_unsupported(self):
         qobj_insts = qobj.experiments[0].instructions
         self.assertFalse(hasattr(qobj_insts[0], "pulse_shape"))
 
+    def test_assemble_parametric_pulse_kwarg_with_backend_setting(self):
+        """Test that parametric pulses respect the kwarg over backend"""
+        backend = FakeAlmaden()
+
+        qc = QuantumCircuit(1, 1)
+        qc.x(0)
+        qc.measure(0, 0)
+        with pulse.build(backend, name="x") as x_q0:
+            pulse.play(pulse.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0))
+
+        qc.add_calibration("x", (0,), x_q0)
+
+        qobj = assemble(qc, backend, parametric_pulses=["gaussian"])
+        self.assertEqual(qobj.config.parametric_pulses, ["gaussian"])
+
+    def test_assemble_parametric_pulse_kwarg_empty_list_with_backend_setting(self):
+        """Test that parametric pulses respect the kwarg as empty list over backend"""
+        backend = FakeAlmaden()
+
+        qc = QuantumCircuit(1, 1)
+        qc.x(0)
+        qc.measure(0, 0)
+        with pulse.build(backend, name="x") as x_q0:
+            pulse.play(pulse.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0))
+
+        qc.add_calibration("x", (0,), x_q0)
+
+        qobj = assemble(qc, backend, parametric_pulses=[])
+        self.assertEqual(qobj.config.parametric_pulses, [])
+
     def test_init_qubits_default(self):
         """Check that the init_qubits=None assemble option is passed on to the qobj."""
         qobj = assemble(self.schedule, self.backend)