Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate pulse Call instruction #10247

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions qiskit/pulse/instructions/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from qiskit.pulse.channels import Channel
from qiskit.pulse.exceptions import PulseError
from qiskit.pulse.instructions import instruction
from qiskit.utils.deprecation import deprecate_func


class Call(instruction.Instruction):
Expand All @@ -30,6 +31,11 @@ class Call(instruction.Instruction):
# Prefix to use for auto naming.
prefix = "call"

@deprecate_func(
since="0.25.0",
additional_msg="Instead, use the pulse builder function "
"qiskit.pulse.builder.call(subroutine) within an active building context.",
)
def __init__(
self,
subroutine,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
deprecations:
- |
The :class:`~qiskit.pulse.instructions.Call` has been deprecated and will
be removed in a future release.
Instead, use the `pulse builder
<https://qiskit.org/documentation/tutorials/circuits_advanced/06_building_pulse_schedules.html>`_
function :func:`~qiskit.pulse.builder.call`
within an active building context.
3 changes: 2 additions & 1 deletion test/python/pulse/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ def test_nested_parametrized_instructions(self):
test_waveform = pulse.Constant(100, self.amp0)

param_sched = pulse.Schedule(pulse.Play(test_waveform, self.d0))
call_inst = pulse.instructions.Call(param_sched)
with self.assertWarns(DeprecationWarning):
call_inst = pulse.instructions.Call(param_sched)

sub_block = pulse.ScheduleBlock()
sub_block += call_inst
Expand Down
15 changes: 10 additions & 5 deletions test/python/pulse/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ def test_scheduler_settings(self):
inst_map.add("x", (0,), test_x_sched)

ref_sched = pulse.Schedule()
ref_sched += pulse.instructions.Call(test_x_sched)
with self.assertWarns(DeprecationWarning):
ref_sched += pulse.instructions.Call(test_x_sched)

x_qc = circuit.QuantumCircuit(2)
x_qc.x(0)
Expand Down Expand Up @@ -961,7 +962,8 @@ def test_call(self):
reference += instructions.Delay(20, d1)

ref_sched = pulse.Schedule()
ref_sched += pulse.instructions.Call(reference)
with self.assertWarns(DeprecationWarning):
ref_sched += pulse.instructions.Call(reference)

with pulse.build() as schedule:
with pulse.align_right():
Expand All @@ -981,7 +983,8 @@ def test_call_circuit(self):
reference = inst_map.get("u1", (0,), 0.0)

ref_sched = pulse.Schedule()
ref_sched += pulse.instructions.Call(reference)
with self.assertWarns(DeprecationWarning):
ref_sched += pulse.instructions.Call(reference)

u1_qc = circuit.QuantumCircuit(2)
u1_qc.append(circuit.library.U1Gate(0.0), [0])
Expand Down Expand Up @@ -1009,7 +1012,8 @@ def test_call_circuit_with_cregs(self):
reference = compiler.schedule(reference_qc, self.backend)

ref_sched = pulse.Schedule()
ref_sched += pulse.instructions.Call(reference)
with self.assertWarns(DeprecationWarning):
ref_sched += pulse.instructions.Call(reference)

self.assertScheduleEqual(schedule, ref_sched)

Expand Down Expand Up @@ -1041,7 +1045,8 @@ def test_call_gate_and_circuit(self):
)

reference = pulse.Schedule()
reference += pulse.instructions.Call(h_reference)
with self.assertWarns(DeprecationWarning):
reference += pulse.instructions.Call(h_reference)
reference += cx_reference
reference += measure_reference << reference.duration

Expand Down
9 changes: 6 additions & 3 deletions test/python/pulse/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,16 @@ def setUp(self):

def test_call(self):
"""Test basic call instruction."""
call = instructions.Call(subroutine=self.subroutine)
with self.assertWarns(DeprecationWarning):
call = instructions.Call(subroutine=self.subroutine)

self.assertEqual(call.duration, 10)
self.assertEqual(call.subroutine, self.subroutine)

def test_parameterized_call(self):
"""Test call instruction with parameterized subroutine."""
call = instructions.Call(subroutine=self.function)
with self.assertWarns(DeprecationWarning):
call = instructions.Call(subroutine=self.function)

self.assertTrue(call.is_parameterized())
self.assertEqual(len(call.parameters), 2)
Expand All @@ -393,7 +395,8 @@ def test_assign_parameters_to_call(self):
def test_call_initialize_with_parameter(self):
"""Test call instruction with parameterized subroutine with initial dict."""
init_dict = {self.param1: 0.1, self.param2: 0.5}
call = instructions.Call(subroutine=self.function, value_dict=init_dict)
with self.assertWarns(DeprecationWarning):
call = instructions.Call(subroutine=self.function, value_dict=init_dict)

with pulse.build() as ref_sched:
pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
Expand Down
33 changes: 22 additions & 11 deletions test/python/pulse/test_parameter_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def setUp(self):
long_schedule += subroutine
long_schedule += pulse.ShiftPhase(self.phi2, self.d2)
long_schedule += pulse.Play(self.parametric_waveform2, self.d2)
long_schedule += pulse.Call(sched)
with self.assertWarns(DeprecationWarning):
long_schedule += pulse.Call(sched)
long_schedule += pulse.Play(self.parametric_waveform3, self.d3)

long_schedule += pulse.Acquire(
Expand Down Expand Up @@ -152,7 +153,8 @@ def test_get_parameter_from_call(self):
sched = pulse.Schedule()
sched += pulse.ShiftPhase(self.phi1, self.d1)

test_obj = pulse.Call(subroutine=sched)
with self.assertWarns(DeprecationWarning):
test_obj = pulse.Call(subroutine=sched)

visitor = ParameterGetter()
visitor.visit(test_obj)
Expand Down Expand Up @@ -257,7 +259,8 @@ def test_set_parameter_to_call(self):
sched = pulse.Schedule()
sched += pulse.ShiftPhase(self.phi1, self.d1)

test_obj = pulse.Call(subroutine=sched)
with self.assertWarns(DeprecationWarning):
test_obj = pulse.Call(subroutine=sched)

value_dict = {self.phi1: 1.57, self.ch1: 2}

Expand All @@ -267,7 +270,8 @@ def test_set_parameter_to_call(self):
ref_sched = pulse.Schedule()
ref_sched += pulse.ShiftPhase(1.57, pulse.DriveChannel(2))

ref_obj = pulse.Call(subroutine=ref_sched)
with self.assertWarns(DeprecationWarning):
ref_obj = pulse.Call(subroutine=ref_sched)

self.assertEqual(assigned, ref_obj)

Expand Down Expand Up @@ -309,7 +313,8 @@ def test_nested_assignment_partial_bind(self):
subroutine += pulse.Play(self.parametric_waveform1, self.d1)

nested_block = pulse.ScheduleBlock()
nested_block += pulse.Call(subroutine=subroutine)
with self.assertWarns(DeprecationWarning):
nested_block += pulse.Call(subroutine=subroutine)

test_obj = pulse.ScheduleBlock()
test_obj += nested_block
Expand Down Expand Up @@ -451,7 +456,8 @@ def test_set_parameter_to_complex_schedule(self):
ref_obj += subroutine
ref_obj += pulse.ShiftPhase(2.0, pulse.DriveChannel(2))
ref_obj += pulse.Play(pulse.Gaussian(125, 0.3, 25), pulse.DriveChannel(2))
ref_obj += pulse.Call(sched)
with self.assertWarns(DeprecationWarning):
ref_obj += pulse.Call(sched)
ref_obj += pulse.Play(pulse.Gaussian(150, 0.4, 25), pulse.DriveChannel(4))

ref_obj += pulse.Acquire(
Expand Down Expand Up @@ -503,12 +509,14 @@ def test_parameters_from_subroutine(self):

# from call instruction
program_layer1 = pulse.Schedule()
program_layer1 += pulse.instructions.Call(program_layer0)
with self.assertWarns(DeprecationWarning):
program_layer1 += pulse.instructions.Call(program_layer0)
self.assertEqual(program_layer1.get_parameters("amp")[0], param1)

# from nested call instruction
program_layer2 = pulse.Schedule()
program_layer2 += pulse.instructions.Call(program_layer1)
with self.assertWarns(DeprecationWarning):
program_layer2 += pulse.instructions.Call(program_layer1)
self.assertEqual(program_layer2.get_parameters("amp")[0], param1)

def test_assign_parameter_to_subroutine(self):
Expand All @@ -522,13 +530,15 @@ def test_assign_parameter_to_subroutine(self):

# to call instruction
program_layer1 = pulse.Schedule()
program_layer1 += pulse.instructions.Call(program_layer0)
with self.assertWarns(DeprecationWarning):
program_layer1 += pulse.instructions.Call(program_layer0)
target = program_layer1.assign_parameters({param1: 0.1}, inplace=False)
self.assertEqual(inline_subroutines(target), reference)

# to nested call instruction
program_layer2 = pulse.Schedule()
program_layer2 += pulse.instructions.Call(program_layer1)
with self.assertWarns(DeprecationWarning):
program_layer2 += pulse.instructions.Call(program_layer1)
target = program_layer2.assign_parameters({param1: 0.1}, inplace=False)
self.assertEqual(inline_subroutines(target), reference)

Expand All @@ -546,7 +556,8 @@ def test_assign_parameter_to_subroutine_parameter(self):

main_prog = pulse.Schedule()
pdict = {param1: param_sub1 + param_sub2}
main_prog += pulse.instructions.Call(subroutine, value_dict=pdict)
with self.assertWarns(DeprecationWarning):
main_prog += pulse.instructions.Call(subroutine, value_dict=pdict)

# parameter is overwritten by parameters
self.assertEqual(len(main_prog.parameters), 2)
Expand Down
12 changes: 8 additions & 4 deletions test/python/pulse/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,12 +907,14 @@ def test_remove_subroutines(self):

subroutine = pulse.Schedule()
subroutine.insert(0, pulse.Delay(20, d0), inplace=True)
subroutine.insert(20, pulse.instructions.Call(nested_routine), inplace=True)
with self.assertWarns(DeprecationWarning):
subroutine.insert(20, pulse.instructions.Call(nested_routine), inplace=True)
subroutine.insert(50, pulse.Delay(10, d0), inplace=True)

main_program = pulse.Schedule()
main_program.insert(0, pulse.Delay(10, d0), inplace=True)
main_program.insert(30, pulse.instructions.Call(subroutine), inplace=True)
with self.assertWarns(DeprecationWarning):
main_program.insert(30, pulse.instructions.Call(subroutine), inplace=True)

target = transforms.inline_subroutines(main_program)

Expand All @@ -932,7 +934,8 @@ def test_call_in_nested_schedule(self):
subroutine.insert(10, pulse.Delay(10, d0), inplace=True)

nested_sched = pulse.Schedule()
nested_sched.insert(0, pulse.instructions.Call(subroutine), inplace=True)
with self.assertWarns(DeprecationWarning):
nested_sched.insert(0, pulse.instructions.Call(subroutine), inplace=True)

main_sched = pulse.Schedule()
main_sched.insert(0, nested_sched, inplace=True)
Expand All @@ -956,7 +959,8 @@ def test_call_in_nested_block(self):
subroutine.append(pulse.Delay(10, d0), inplace=True)

nested_block = pulse.ScheduleBlock()
nested_block.append(pulse.instructions.Call(subroutine), inplace=True)
with self.assertWarns(DeprecationWarning):
nested_block.append(pulse.instructions.Call(subroutine), inplace=True)

main_block = pulse.ScheduleBlock()
main_block.append(nested_block, inplace=True)
Expand Down