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

Pulse builder interface #4174

Merged
merged 294 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
294 commits
Select commit Hold shift + click to select a range
ecf32be
Fix setting contexts.
taalexander Apr 2, 2020
3a3420b
Make builder class private.
taalexander Apr 2, 2020
ba95adf
Add group transform.
taalexander Apr 3, 2020
d8aff87
Initial demo test is running (not necessarily doing the right thing.
taalexander Apr 3, 2020
b2a5bde
Typed context gate call parameters.
taalexander Apr 3, 2020
9318dcc
Fix imports for builder.
taalexander Apr 3, 2020
a3163c5
Fix bugs in tests.
taalexander Apr 3, 2020
1f45184
Minor changes.
taalexander Apr 5, 2020
c32093a
Add pad context. Rename active -> current.
taalexander Apr 5, 2020
8562b00
Add barrier test, expected fail.
taalexander Apr 6, 2020
84e0c0b
Added group context test.
taalexander Apr 6, 2020
b04bc26
Fix bug in acquire instruction.
taalexander Apr 7, 2020
6b61868
Add instruction tests.
taalexander Apr 7, 2020
3c6f7b9
Add builder utilities tests.
taalexander Apr 7, 2020
2256c09
Fix bug in scheduler when no gates present in circuit.
taalexander Apr 7, 2020
bb61a95
Test transpiler and scheduler context settings / utilities.
taalexander Apr 7, 2020
570c470
Made children, a public method.
taalexander Apr 7, 2020
2b8aa97
add default alignment context for builder.
taalexander Apr 7, 2020
1d1291f
Get tests working for call_schedule and call_circuit. Rework right al…
taalexander Apr 7, 2020
9981ebf
Rename test file.
taalexander Apr 7, 2020
866981e
Test measure macro.
taalexander Apr 7, 2020
c96bc47
Add delay_qubit macro test.
taalexander Apr 7, 2020
e80cffe
Update context builder test docstring.
taalexander Apr 7, 2020
3e6be9b
Review suggestions
SooluThomas Apr 7, 2020
3827a66
Add gate tests. Running into a bug with the schedule implementation.
taalexander Apr 7, 2020
204b836
Fix get_qubit_channels
SooluThomas Apr 7, 2020
0aa28e9
Merge remote-tracking branch 'upstream/master' into pulse-builder-int…
taalexander Apr 7, 2020
b7dfccb
Fix bug in acquire round 2.
taalexander Apr 7, 2020
fe2c9c0
Deprecation warning to use control(qubits: List) instead of control(c…
SooluThomas Apr 7, 2020
da37871
Fix mutable insert flattening schedule tree.
taalexander Apr 7, 2020
a4b32e9
Fix delay test using qubit index.
taalexander Apr 7, 2020
637d2cc
Fix using deprecated cnotgate.
taalexander Apr 7, 2020
26a4ad0
typos
SooluThomas Apr 7, 2020
4fa0f09
Rename alignment contexts.
taalexander Apr 8, 2020
8cb4551
update the control based on the new backend schema
SooluThomas Apr 8, 2020
0dcf6fd
typos
SooluThomas Apr 8, 2020
967a99b
Unify alignment context naming.
taalexander Apr 8, 2020
0d6ea09
Merge branch 'master' into add/control-channel
SooluThomas Apr 8, 2020
5a5fe97
Unify naming of transforms and fix broken align_right.
taalexander Apr 8, 2020
c2649b4
More logic fixes
SooluThomas Apr 9, 2020
b5b90fa
lint
SooluThomas Apr 9, 2020
d8fb7a8
lint
SooluThomas Apr 9, 2020
73433e9
fix merge conflicts
SooluThomas Apr 10, 2020
f502ac2
add older code
SooluThomas Apr 10, 2020
74c7f0a
Merge branch 'master' of https://github.com/Qiskit/qiskit-terra into …
SooluThomas Apr 10, 2020
9f611de
More logic fixes
SooluThomas Apr 10, 2020
0387399
lint
SooluThomas Apr 10, 2020
fe79617
Update docstrings and typehints
SooluThomas Apr 10, 2020
2697479
Unused imports
SooluThomas Apr 10, 2020
a87addd
Merge branch 'master' of https://github.com/Qiskit/qiskit-terra into …
SooluThomas Apr 13, 2020
3e146cf
Release notes
SooluThomas Apr 13, 2020
0da2877
Review suggestions
SooluThomas Apr 13, 2020
7b6adf5
Merge branch 'master' of https://github.com/Qiskit/qiskit-terra into …
SooluThomas Apr 13, 2020
641a0aa
Bug fix for get_qubit_channels(0)
SooluThomas Apr 14, 2020
e3e4649
Review Suggestions
SooluThomas Apr 14, 2020
b4d0bc5
lint
SooluThomas Apr 14, 2020
d2104bc
Change error message of _get_channel_prefix_index
SooluThomas Apr 14, 2020
69bde8a
Added raise error for backends without 'channel' information
SooluThomas Apr 14, 2020
0d2865e
Update docstrings for raise errors
SooluThomas Apr 14, 2020
ba5e310
Fix error messages and docstrings
SooluThomas Apr 14, 2020
b67d336
Merge branch 'master' into add/control-channel
SooluThomas Apr 14, 2020
237036a
Merge branch 'master' of https://github.com/Qiskit/qiskit-terra into …
SooluThomas Apr 15, 2020
6e4111a
make self.channels private
SooluThomas Apr 15, 2020
15ffa06
Merge branch 'add/control-channel' of https://github.com/SooluThomas/…
SooluThomas Apr 15, 2020
d602738
Remove collections.Counter
SooluThomas Apr 15, 2020
b116ba5
Revert "Remove collections.Counter"
SooluThomas Apr 15, 2020
7540b0c
Add complex test.
taalexander Apr 15, 2020
4f07bbe
Rename _schedule_lazy_circuit_before to _compile_lazy_circuit_before
taalexander Apr 15, 2020
c880f75
Merge remote-tracking branch 'soolu/add/control-channel' into pulse-b…
taalexander Apr 15, 2020
603bf2c
Add delay_qubits instruction. Fix bug in schedule equality test.
taalexander Apr 15, 2020
2f2262a
Add frequency and phase offset contexts.
taalexander Apr 15, 2020
e36da24
Renamed builder_context to builder.
taalexander Apr 15, 2020
eed4302
Add inline directive.
taalexander Apr 15, 2020
2a57050
linting.
taalexander Apr 16, 2020
265dcb2
Fix linting errors.
taalexander Apr 16, 2020
680f480
Add rescheduler linting.
taalexander Apr 16, 2020
1979172
Add transforms documentation.
taalexander Apr 16, 2020
f1577f9
Lint test builder.
taalexander Apr 16, 2020
ab300f7
Add macro linting.
taalexander Apr 16, 2020
3c6a60e
Schedule linting.
taalexander Apr 16, 2020
af8713e
lint pulse builder.
taalexander Apr 16, 2020
c151740
Remove cyclical imports with compiler import in pulse builder.
taalexander Apr 17, 2020
5aedb08
Add channel builder helper functions. Rename current to active.
taalexander Apr 17, 2020
04527a9
Add relative barrier directive.
taalexander Apr 17, 2020
0ca803a
Refactor visualization namespacing.
taalexander Apr 17, 2020
c5caf62
Add barrier directive to builder.
taalexander Apr 17, 2020
9b875e6
Add num_qubits.
taalexander Apr 17, 2020
1c0a46e
Add measure_all builder command.
taalexander Apr 17, 2020
bb01b31
Add acquire on qubit.
taalexander Apr 17, 2020
d7275d8
Add error if not all channels supplied to an Instruction is a channel.
taalexander Apr 18, 2020
a1c3253
Remove notebooks directory from hackathon.
taalexander Apr 18, 2020
17dab14
Merge remote-tracking branch 'upstream/master' into pulse-builder-int…
taalexander Apr 18, 2020
8caaab1
linting
taalexander Apr 18, 2020
815ffac
Fix issue with deprecated Delay.
taalexander Apr 18, 2020
0442c19
Add backport packages for contextvars.
taalexander Apr 18, 2020
fe0bc3b
Reorder schedule and backend arguments. Make backend no longer required.
taalexander Apr 18, 2020
666a1fc
Small builder doc update.
taalexander Apr 18, 2020
9317ca6
Add simpler calling syntax for the builder.
taalexander Apr 18, 2020
e4fcd92
Fix python versioninign.
taalexander Apr 18, 2020
2e63ea6
Add __all__ for builder.
taalexander Apr 19, 2020
08f357d
Add exceptions for no active builder or no backend set.
taalexander Apr 19, 2020
7c4860c
Update automodule
SooluThomas Apr 21, 2020
ebc1475
Remove unwanted docstrings
SooluThomas Apr 21, 2020
a10426b
Fix pylint error - BackendNotSet not added in docstring
SooluThomas Apr 21, 2020
59d45fe
Fix weird bug
SooluThomas Apr 21, 2020
3e8811d
Fix 'commands' not imported
SooluThomas Apr 21, 2020
4ec0e35
Fix typo
SooluThomas Apr 21, 2020
0d331de
Merge pull request #3 from SooluThomas/pulse-builder-interface
taalexander Apr 24, 2020
49fc9f1
Rename pulse.reschedule -> pulse.transforms
lcapelluto Apr 28, 2020
53190ca
Update surrounding code to support rename (releasenotes, add reschedu…
lcapelluto Apr 24, 2020
d429bc4
Remove unwanted newlines
lcapelluto Apr 28, 2020
62f8a64
Reapply feedback from code review
lcapelluto Apr 28, 2020
0c07b88
Merge branch 'master' into rename-rescheduler-to-transform
taalexander Apr 28, 2020
426d689
Add test cases for issues with timeslots.'
taalexander Apr 28, 2020
469e583
Fix small bug in timeslot insertion finder.
taalexander Apr 28, 2020
23cee76
Fixed another error in the code path.
taalexander Apr 29, 2020
99382cc
Remove accidental comment.
taalexander Apr 29, 2020
b8283a8
Merge branch 'master' into pulse-builder-interface
taalexander Apr 28, 2020
415ab7a
Merge remote-tracking branch 'upstream/master' into HEAD
taalexander Apr 29, 2020
419c824
Restructure code during bug hunting.
taalexander Apr 30, 2020
d00c004
Fix another small timeslot bug.
taalexander Apr 30, 2020
00ebc61
Fix small issue.
taalexander Apr 30, 2020
b7ce921
Moved circuit_scheduler back to scheduler.
taalexander Apr 30, 2020
adbd53a
Merge remote-tracking branch 'upstream/master' into pulse-builder-int…
taalexander Apr 30, 2020
b0d9377
Properly deprecate scheduler utils.
taalexander Apr 30, 2020
a7ce1a3
linting
taalexander Apr 30, 2020
b3c21cc
Fix missed pieces when moving back scheduler.
taalexander Apr 30, 2020
5f68175
Fix circular imports by using from instead of import
taalexander Apr 30, 2020
5c9eadc
linting.
taalexander May 1, 2020
6b84f83
use Constant instead of ConstantPulse.
taalexander May 1, 2020
e7e2929
Rename pulse.reschedule -> pulse.transforms
lcapelluto Apr 28, 2020
aadc2a3
Update surrounding code to support rename (releasenotes, add reschedu…
lcapelluto Apr 24, 2020
50d6f39
Remove unwanted newlines
lcapelluto Apr 28, 2020
615d814
Reapply feedback from code review
lcapelluto Apr 28, 2020
a087567
Fix docs unexpected indent
lcapelluto Apr 30, 2020
5c84fd0
Merge remote-tracking branch 'lauren/rename-rescheduler-to-transform'…
taalexander May 4, 2020
ddb3581
Linting.
taalexander May 1, 2020
7af8eb1
Change deprecation warning to emit warning at proper stack location.
taalexander May 1, 2020
48d773b
Make changes to remove deprecation warnings.
taalexander May 1, 2020
cb3bc07
Remove leftover files from moving of scheduler.
taalexander May 1, 2020
a0034ae
Revert ordering of channel and qubit arguments compared to parameters.
taalexander May 1, 2020
0bc4210
Add pulse builder documentation.
taalexander May 1, 2020
b3aa89a
fix up builder tests.
taalexander May 1, 2020
b58f03e
Linting.
taalexander May 2, 2020
8eb8882
Docs update.
taalexander May 2, 2020
aadfb70
Fix deprecation warning.
taalexander May 2, 2020
7d6c1f8
Fix reno warnings
SooluThomas May 4, 2020
a135c58
Some builder.py docstring updates
SooluThomas May 4, 2020
55c55d1
Documentation updates.
taalexander May 4, 2020
8bba202
Fix issue with wrapped function not being properly documented.
taalexander May 4, 2020
3313177
Update builder docs to use jupyter-executer
taalexander May 4, 2020
444d4de
Builder interface documentation.
taalexander May 5, 2020
567b8a5
Fix issue with pulse barrier padding.
taalexander May 5, 2020
1c03002
Merge remote-tracking branch 'upstream/master' into pulse-builder-int…
taalexander May 5, 2020
e06bb01
Fix builder barrier doc.
taalexander May 5, 2020
235ad59
Structure builder imports.
taalexander May 5, 2020
8914ee0
Update qiskit/pulse/instructions/directives.py
taalexander May 7, 2020
f49a77b
Update qiskit/pulse/instructions/acquire.py
taalexander May 7, 2020
c2e4211
Update qiskit/pulse/instructions/directives.py
taalexander May 7, 2020
9ccecc3
Fix call circuit.
taalexander May 8, 2020
802020e
Enable a samples_to_time and time_to_samples method.
taalexander May 8, 2020
c20038a
Add test to builder for calling circuit with cregs.
taalexander May 8, 2020
3bb6cd7
Merge remote-tracking branch 'origin/pulse-builder-interface' into pu…
taalexander May 8, 2020
242c934
Update qiskit/pulse/builder.py
taalexander May 8, 2020
49aac30
Update qiskit/pulse/builder.py
taalexander May 8, 2020
0023192
Update qiskit/pulse/builder.py
taalexander May 8, 2020
bd508f7
Revert acquire import changes.
taalexander May 11, 2020
fe27eb6
Ignore trivial barriers.
taalexander May 11, 2020
1ccad51
Add note on future deprecation of calling gates within the pulse buil…
taalexander May 11, 2020
e9ea2ec
Remove commented out execution.
taalexander May 12, 2020
15a1166
Update qiskit/pulse/transforms.py
taalexander May 12, 2020
71ddec3
Remove mention of quantum circuit in builder documentation intro.
taalexander May 12, 2020
40fe25d
Update qiskit/pulse/builder.py
taalexander May 12, 2020
90835ee
Fix jupyter execute import style.
taalexander May 12, 2020
4804a9e
Fix unclear arguments in delay_qubits doc.
taalexander May 12, 2020
3f1482e
Make pulse builder warning more prominent and revise message.
taalexander May 12, 2020
98485b4
Fixed import asthetic.
taalexander May 12, 2020
c93bdd9
Move BackendNotSet to exceptions.
taalexander May 12, 2020
79425cb
Fix more asthetic setting of default settings in builder.
taalexander May 12, 2020
f959369
Merge remote-tracking branch 'origin/pulse-builder-interface' into pu…
taalexander May 12, 2020
0d7407d
Remove left over assert in builder.
taalexander May 13, 2020
c196f5d
Remove dead comment.
taalexander May 13, 2020
d0fc231
Reorder _call_circuit.
taalexander May 13, 2020
62e71f5
Fix small linting error
taalexander May 13, 2020
02b1c31
Fix commented out example code.
taalexander May 13, 2020
f3dac18
Remove comment headers.
taalexander May 13, 2020
2cd116b
Move NoActiveBuilder exception to exceptions.
taalexander May 13, 2020
58e7aca
Rename time to sample and vice versa to seconds to samples
taalexander May 13, 2020
2a3a9ba
Update macros module docstring.
taalexander May 13, 2020
37f5398
Fix measure docstring spacing.
taalexander May 13, 2020
09d566a
Update test_builder copyright.
taalexander May 13, 2020
732721e
Fix test docstrings.
taalexander May 13, 2020
fac20d9
Add notes for expected test failures.
taalexander May 13, 2020
df2f2b6
Rename types sections to channels.
taalexander May 13, 2020
0bd2ae7
Fix test spacing.
taalexander May 13, 2020
40054c2
Revert test modification.
taalexander May 13, 2020
de754ed
Fix test_transform docstring.
taalexander May 13, 2020
fd5854b
Add better coverage for TestRemoveTrivialBarriers
taalexander May 13, 2020
11065b0
Readd transform tests.
taalexander May 13, 2020
0b5a84a
Merge remote-tracking branch 'upstream/master' into pulse-builder-int…
taalexander May 13, 2020
05c0732
Change example usage to examples for uniformity.
taalexander May 14, 2020
80fb222
linting invalid name.
taalexander May 14, 2020
0dcdc29
Replace mutate flag with inplace to mirror the circuit model.
taalexander Jun 2, 2020
150cf83
Allow passing name to pulse.build.
taalexander Jun 2, 2020
538a100
Fix bad builder example assert.
taalexander Jun 2, 2020
9f0d254
Allow frequency and phase offset contexts to broacast across channels.
taalexander Jun 2, 2020
408c2ea
Merge remote-tracking branch 'upstream/master' into pulse-builder-int…
taalexander Jun 2, 2020
c53ca20
Revert delay instruction error.
taalexander Jun 2, 2020
185e00a
Remove unnecessary assignments for inplace schedule operations.
taalexander Jun 2, 2020
09d7f87
Reorder sequential transform reference ordering.
taalexander Jun 2, 2020
8230000
Removed unnecessary removal of barriers in transform test.
taalexander Jun 2, 2020
aabe54b
Verify that flattened works correctly by testing aligned on grouped s…
taalexander Jun 2, 2020
4a47f56
Make align right test depending on nesting. Refactor implementation o…
taalexander Jun 3, 2020
2a0130f
Use append instead of append where it makes sense. Use inplace where …
taalexander Jun 3, 2020
a2cda9e
Remove the pulse group instruction for now.
taalexander Jun 3, 2020
3da37a4
Added better inlining test.
taalexander Jun 3, 2020
e2fb31d
Implement shift frequency and frequency_offset.
taalexander Jun 3, 2020
0752e21
Clean up builder tests #1
taalexander Jun 3, 2020
ef6b26d
Deprecate warns only once.
taalexander Jun 3, 2020
b3c986d
Remove append_instruction from pulse namespace.
taalexander Jun 3, 2020
8f1ad27
Fix bad test name in test_instructions.
taalexander Jun 3, 2020
6517ed9
Added beta flag.
taalexander Jun 3, 2020
13139c4
Update flatten transform documentation.
taalexander Jun 4, 2020
8a47413
Operator spaces.
taalexander Jun 4, 2020
ca0ff12
Fix unnecessary else in schedule.
taalexander Jun 4, 2020
583d649
Fix operator spacing in test-transforms.
taalexander Jun 4, 2020
276e834
time to seconds
taalexander Jun 4, 2020
488b6b3
Fix misnamed test.
taalexander Jun 4, 2020
b8c897c
Revert children to _children.
taalexander Jun 4, 2020
6287320
Update pulse module docstring
taalexander Jun 4, 2020
019504d
Merge remote-tracking branch 'upstream/master' into pulse-builder-int…
taalexander Jun 4, 2020
8ae5497
linting.
taalexander Jun 4, 2020
9b76085
Revert apidocs change in pulse.
taalexander Jun 19, 2020
0a55da2
Remove call_schedule, call_circuit, call_gate from top-level import.
taalexander Jun 19, 2020
513d574
Rename block to context_schedule.
taalexander Jun 19, 2020
8625c29
Better error message.
taalexander Jun 19, 2020
ff366ae
Fix module level import.
taalexander Jun 19, 2020
f9ec513
revert reno files.
taalexander Jun 19, 2020
ac100b2
Added space in test builder.
taalexander Jun 19, 2020
b9cfa72
Merge remote-tracking branch 'upstream/master' into pulse-builder-int…
taalexander Jun 19, 2020
3bbf761
Added set_phase instruction.
taalexander Jun 19, 2020
b0591cd
Revert visualization changes.
taalexander Jun 19, 2020
36098a5
Remove unused import
taalexander Jun 19, 2020
7e86d04
Standardize imports for builder PR.
taalexander Jun 19, 2020
2e08fcc
Docs updates.
taalexander Jun 19, 2020
3df7a28
Merge remote-tracking branch 'upstream/master' into pulse-builder-int…
taalexander Jul 6, 2020
7c25808
Merge branch 'master' into pulse-builder-interface
mergify[bot] Jul 8, 2020
fa0cdbd
Merge branch 'master' into pulse-builder-interface
mergify[bot] Jul 8, 2020
209a482
Merge branch 'master' into pulse-builder-interface
mergify[bot] Jul 8, 2020
63d99fa
Merge branch 'master' into pulse-builder-interface
SooluThomas Jul 8, 2020
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
8 changes: 4 additions & 4 deletions qiskit/assembler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
RunConfig
"""

from .assemble_circuits import assemble_circuits
from .assemble_schedules import assemble_schedules
from .disassemble import disassemble
from .run_config import RunConfig
from qiskit.assembler.assemble_circuits import assemble_circuits
from qiskit.assembler.assemble_schedules import assemble_schedules
from qiskit.assembler.disassemble import disassemble
from qiskit.assembler.run_config import RunConfig
134 changes: 70 additions & 64 deletions qiskit/assembler/assemble_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,18 @@
from typing import Any, Dict, List, Tuple
taalexander marked this conversation as resolved.
Show resolved Hide resolved
import hashlib

from qiskit import qobj, pulse
from qiskit.assembler.run_config import RunConfig
from qiskit.exceptions import QiskitError
from qiskit.pulse import Schedule, Acquire, Delay, Play, transforms
from qiskit.pulse.pulse_lib import ParametricPulse, SamplePulse
from qiskit.pulse.commands import (Command, PulseInstruction, AcquireInstruction,
DelayInstruction, ParametricInstruction)
from qiskit.qobj import (PulseQobj, QobjHeader, QobjExperimentHeader,
PulseQobjInstruction, PulseQobjExperimentConfig,
PulseQobjExperiment, PulseQobjConfig, PulseLibraryItem)
from qiskit.qobj.converters import InstructionToQobjConverter, LoConfigConverter
from qiskit.pulse import instructions, transforms, pulse_lib, commands
from qiskit.qobj import utils as qobj_utils, converters
from qiskit.qobj.converters.pulse_instruction import ParametricPulseShapes
from qiskit.qobj.utils import MeasLevel, MeasReturnType

from .run_config import RunConfig


def assemble_schedules(schedules: List[Schedule],
def assemble_schedules(schedules: List[pulse.Schedule],
qobj_id: int,
qobj_header: QobjHeader,
run_config: RunConfig) -> PulseQobj:
qobj_header: qobj.QobjHeader,
run_config: RunConfig) -> qobj.PulseQobj:
"""Assembles a list of schedules into a qobj that can be run on the backend.

Args:
Expand All @@ -55,24 +48,24 @@ def assemble_schedules(schedules: List[Schedule],
if not hasattr(run_config, 'meas_lo_freq'):
raise QiskitError('meas_lo_freq must be supplied.')

lo_converter = LoConfigConverter(PulseQobjExperimentConfig,
**run_config.to_dict())
lo_converter = converters.LoConfigConverter(qobj.PulseQobjExperimentConfig,
**run_config.to_dict())
experiments, experiment_config = _assemble_experiments(schedules,
lo_converter,
run_config)
qobj_config = _assemble_config(lo_converter, experiment_config, run_config)

return PulseQobj(experiments=experiments,
qobj_id=qobj_id,
header=qobj_header,
config=qobj_config)
return qobj.PulseQobj(experiments=experiments,
qobj_id=qobj_id,
header=qobj_header,
config=qobj_config)


def _assemble_experiments(
schedules: List[Schedule],
lo_converter: LoConfigConverter,
schedules: List[pulse.Schedule],
lo_converter: converters.LoConfigConverter,
run_config: RunConfig
) -> Tuple[List[PulseQobjExperiment], Dict[str, Any]]:
) -> Tuple[List[qobj.PulseQobjExperiment], Dict[str, Any]]:
"""Assembles a list of schedules into PulseQobjExperiments, and returns related metadata that
will be assembled into the Qobj configuration.

Expand All @@ -95,8 +88,11 @@ def _assemble_experiments(
'schedule, or a list of frequencies should be provided for a single '
'frequency sweep schedule.')

instruction_converter = getattr(run_config, 'instruction_converter', InstructionToQobjConverter)
instruction_converter = instruction_converter(PulseQobjInstruction, **run_config.to_dict())
instruction_converter = getattr(run_config,
'instruction_converter',
converters.InstructionToQobjConverter)
instruction_converter = instruction_converter(qobj.PulseQobjInstruction,
**run_config.to_dict())
compressed_schedules = transforms.compress_pulses(schedules)

user_pulselib = {}
Expand All @@ -109,11 +105,11 @@ def _assemble_experiments(
user_pulselib)

# TODO: add other experimental header items (see circuit assembler)
qobj_experiment_header = QobjExperimentHeader(
qobj_experiment_header = qobj.QobjExperimentHeader(
memory_slots=max_memory_slot + 1, # Memory slots are 0 indexed
name=schedule.name or 'Experiment-%d' % idx)

experiment = PulseQobjExperiment(
experiment = qobj.PulseQobjExperiment(
header=qobj_experiment_header,
instructions=qobj_instructions)
if freq_configs:
Expand All @@ -129,14 +125,14 @@ def _assemble_experiments(
experiment = experiments[0]
experiments = []
for freq_config in freq_configs:
experiments.append(PulseQobjExperiment(
experiments.append(qobj.PulseQobjExperiment(
header=experiment.header,
instructions=experiment.instructions,
config=freq_config))

# Top level Qobj configuration
experiment_config = {
'pulse_library': [PulseLibraryItem(name=name, samples=samples)
'pulse_library': [qobj.PulseLibraryItem(name=name, samples=samples)
for name, samples in user_pulselib.items()],
'memory_slots': max([exp.header.memory_slots for exp in experiments])
}
Expand All @@ -145,11 +141,11 @@ def _assemble_experiments(


def _assemble_instructions(
schedule: Schedule,
instruction_converter: InstructionToQobjConverter,
schedule: pulse.Schedule,
instruction_converter: converters.InstructionToQobjConverter,
run_config: RunConfig,
user_pulselib: Dict[str, Command]
) -> Tuple[List[PulseQobjInstruction], int]:
user_pulselib: Dict[str, commands.Command]
) -> Tuple[List[qobj.PulseQobjInstruction], int]:
"""Assembles the instructions in a schedule into a list of PulseQobjInstructions and returns
related metadata that will be assembled into the Qobj configuration. Lookup table for
pulses defined in all experiments are registered in ``user_pulselib``. This object should be
Expand All @@ -173,36 +169,45 @@ def _assemble_instructions(
acquire_instruction_map = defaultdict(list)
for time, instruction in schedule.instructions:

if isinstance(instruction, ParametricInstruction): # deprecated
instruction = Play(instruction.command, instruction.channels[0], name=instruction.name)
if isinstance(instruction, commands.ParametricInstruction): # deprecated
instruction = instructions.Play(instruction.command,
instruction.channels[0],
name=instruction.name)

if isinstance(instruction, Play) and isinstance(instruction.pulse, ParametricPulse):
if (isinstance(instruction, instructions.Play) and
isinstance(instruction.pulse, pulse_lib.ParametricPulse)):
pulse_shape = ParametricPulseShapes(type(instruction.pulse)).name
if pulse_shape not in run_config.parametric_pulses:
instruction = Play(instruction.pulse.get_sample_pulse(),
instruction.channel,
name=instruction.name)

if isinstance(instruction, PulseInstruction): # deprecated
instruction = Play(SamplePulse(name=name, samples=instruction.command.samples),
instruction.channels[0], name=name)

if isinstance(instruction, Play) and isinstance(instruction.pulse, SamplePulse):
instruction = instructions.Play(instruction.pulse.get_sample_pulse(),
instruction.channel,
name=instruction.name)

if isinstance(instruction, commands.PulseInstruction): # deprecated
name = instruction.command.name
instruction = instructions.Play(
pulse_lib.SamplePulse(name=name, samples=instruction.command.samples),
instruction.channels[0], name=name)

if (isinstance(instruction, instructions.Play) and
isinstance(instruction.pulse, pulse_lib.SamplePulse)):
name = hashlib.sha256(instruction.pulse.samples).hexdigest()
instruction = Play(SamplePulse(name=name, samples=instruction.pulse.samples),
channel=instruction.channel,
name=name)
instruction = instructions.Play(
pulse_lib.SamplePulse(name=name, samples=instruction.pulse.samples),
channel=instruction.channel,
name=name)
user_pulselib[name] = instruction.pulse.samples

if isinstance(instruction, (AcquireInstruction, Acquire)):
if isinstance(instruction, (commands.AcquireInstruction, instructions.Acquire)):
if instruction.mem_slot:
max_memory_slot = max(max_memory_slot, instruction.mem_slot.index)
# Acquires have a single AcquireChannel per inst, but we have to bundle them
# together into the Qobj as one instruction with many channels
acquire_instruction_map[(time, instruction.command)].append(instruction)
continue

if isinstance(instruction, (DelayInstruction, Delay)):
if isinstance(instruction, (commands.DelayInstruction,
instructions.Delay,
instructions.Directive)):
# delay instructions are ignored as timing is explicit within qobj
continue

Expand All @@ -211,17 +216,18 @@ def _assemble_instructions(
if acquire_instruction_map:
if hasattr(run_config, 'meas_map'):
_validate_meas_map(acquire_instruction_map, run_config.meas_map)
for (time, _), instructions in acquire_instruction_map.items():
qubits, mem_slots, reg_slots = _bundle_channel_indices(instructions)
for (time, _), instrs in acquire_instruction_map.items():
qubits, mem_slots, reg_slots = _bundle_channel_indices(instrs)
qobj_instructions.append(
instruction_converter.convert_single_acquires(
time, instructions[0],
time, instrs[0],
qubits=qubits, memory_slot=mem_slots, register_slot=reg_slots))

return qobj_instructions, max_memory_slot


def _validate_meas_map(instruction_map: Dict[Tuple[int, Acquire], List[AcquireInstruction]],
def _validate_meas_map(instruction_map: Dict[Tuple[int, instructions.Acquire],
List[commands.AcquireInstruction]],
meas_map: List[List[int]]) -> None:
"""Validate all qubits tied in ``meas_map`` are to be acquired.

Expand All @@ -236,9 +242,9 @@ def _validate_meas_map(instruction_map: Dict[Tuple[int, Acquire], List[AcquireIn
meas_map_sets = [set(m) for m in meas_map]

# Check each acquisition time individually
for _, instructions in instruction_map.items():
for _, instrs in instruction_map.items():
measured_qubits = set()
for inst in instructions:
for inst in instrs:
measured_qubits.add(inst.channel.index)

for meas_set in meas_map_sets:
Expand All @@ -249,21 +255,21 @@ def _validate_meas_map(instruction_map: Dict[Tuple[int, Acquire], List[AcquireIn


def _bundle_channel_indices(
instructions: List[AcquireInstruction]
instrs: List[commands.AcquireInstruction]
) -> Tuple[List[int], List[int], List[int]]:
"""From the list of AcquireInstructions, bundle the indices of the acquire channels,
memory slots, and register slots into a 3-tuple of lists.

Args:
instructions: A list of AcquireInstructions to be bundled.
instrs: A list of AcquireInstructions to be bundled.

Returns:
The qubit indices, the memory slot indices, and register slot indices from instructions.
"""
qubits = []
mem_slots = []
reg_slots = []
for inst in instructions:
for inst in instrs:
qubits.append(inst.channel.index)
if inst.mem_slot:
mem_slots.append(inst.mem_slot.index)
Expand All @@ -272,9 +278,9 @@ def _bundle_channel_indices(
return qubits, mem_slots, reg_slots


def _assemble_config(lo_converter: LoConfigConverter,
def _assemble_config(lo_converter: converters.LoConfigConverter,
experiment_config: Dict[str, Any],
run_config: RunConfig) -> PulseQobjConfig:
run_config: RunConfig) -> qobj.PulseQobjConfig:
"""Assembles the QobjConfiguration from experimental config and runtime config.

Args:
Expand All @@ -295,11 +301,11 @@ def _assemble_config(lo_converter: LoConfigConverter,

# convert enums to serialized values
meas_return = qobj_config.get('meas_return', 'avg')
if isinstance(meas_return, MeasReturnType):
if isinstance(meas_return, qobj_utils.MeasReturnType):
qobj_config['meas_return'] = meas_return.value

meas_level = qobj_config.get('meas_level', 2)
if isinstance(meas_level, MeasLevel):
if isinstance(meas_level, qobj_utils.MeasLevel):
qobj_config['meas_level'] = meas_level.value

# convert lo frequencies to Hz
Expand All @@ -318,4 +324,4 @@ def _assemble_config(lo_converter: LoConfigConverter,
if m_los:
qobj_config['meas_lo_freq'] = [freq / 1e9 for freq in m_los]

return PulseQobjConfig(**qobj_config)
return qobj.PulseQobjConfig(**qobj_config)
3 changes: 2 additions & 1 deletion qiskit/compiler/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from qiskit.exceptions import QiskitError
from qiskit.pulse import InstructionScheduleMap, Schedule
from qiskit.providers import BaseBackend
from qiskit.scheduler import schedule_circuit, ScheduleConfig
taalexander marked this conversation as resolved.
Show resolved Hide resolved
from qiskit.scheduler import ScheduleConfig
from qiskit.scheduler.schedule_circuit import schedule_circuit

LOG = logging.getLogger(__name__)

Expand Down
Loading