qiskit-documentation/docs/api/qiskit/0.31/qiskit.pulse.builder.call.mdx

79 lines
3.1 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: call
description: API reference for qiskit.pulse.builder.call
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.pulse.builder.call
---
# qiskit.pulse.builder.call
<Function id="qiskit.pulse.builder.call" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.18/qiskit/pulse/builder.py" signature="call(target, name=None, value_dict=None, **kw_params)">
Call the `target` within the currently active builder context with arbitrary parameters which will be assigned to the target program.
<Admonition title="Note" type="note">
The `target` program is inserted as a `Call` instruction. This instruction defines a subroutine. See [`Call`](qiskit.pulse.instructions.Call "qiskit.pulse.instructions.Call") for more details.
</Admonition>
Examples:
```python
from qiskit import circuit, pulse, schedule, transpile
from qiskit.test.mock import FakeOpenPulse2Q
backend = FakeOpenPulse2Q()
qc = circuit.QuantumCircuit(2)
qc.cx(0, 1)
qc_transpiled = transpile(qc, optimization_level=3)
sched = schedule(qc_transpiled, backend)
with pulse.build(backend) as pulse_prog:
pulse.call(sched)
pulse.call(qc)
```
This function can optionally take parameter dictionary with the parameterized target program.
```python
from qiskit import circuit, pulse
amp = circuit.Parameter('amp')
with pulse.build() as subroutine:
pulse.play(pulse.Gaussian(160, amp, 40), pulse.DriveChannel(0))
with pulse.build() as main_prog:
pulse.call(subroutine, amp=0.1)
pulse.call(subroutine, amp=0.3)
```
If there is any parameter name collision, you can distinguish them by specifying each parameter object as a python dictionary. Otherwise `amp1` and `amp2` will be updated with the same value.
```python
from qiskit import circuit, pulse
amp1 = circuit.Parameter('amp')
amp2 = circuit.Parameter('amp')
with pulse.build() as subroutine:
pulse.play(pulse.Gaussian(160, amp1, 40), pulse.DriveChannel(0))
pulse.play(pulse.Gaussian(160, amp2, 40), pulse.DriveChannel(1))
with pulse.build() as main_prog:
pulse.call(subroutine, value_dict={amp1: 0.1, amp2: 0.2})
```
**Parameters**
* **target** (`Union`\[`QuantumCircuit`, `Schedule`, `ScheduleBlock`]) Target circuit or pulse schedule to call.
* **name** (`Optional`\[`str`]) Name of subroutine if defined.
* **value\_dict** (`Optional`\[`Dict`\[`Union`\[`ParameterExpression`, `float`], `Union`\[`ParameterExpression`, `float`]]]) Parameter object and assigned value mapping. This is more precise way to identify a parameter since mapping is managed with unique object id rather than name. Especially there is any name collision in a parameter table.
* **kw\_params** (`Union`\[`ParameterExpression`, `float`]) Parameter values to bind to the target subroutine with string parameter names. If there are parameter name overlapping, these parameters are updated with the same assigned value.
**Raises**
**exceptions.PulseError** If the input `target` type is not supported.
</Function>