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 Compiler SetSequence pass #11980

Merged
merged 18 commits into from
Mar 12, 2024

Conversation

TsafrirA
Copy link
Collaborator

@TsafrirA TsafrirA commented Mar 9, 2024

Summary

A SetSequence pass is introduced. The pass transforms Pulse's SequenceIR by setting the sequence of elements (adding edges to the graph). A second analysis pass is introduced - MapMixedFrame - which is needed for sequencing of parallel alignments.

Details and comments

When SequenceIR object is populated, its sequence property includes only nodes and no edges. Setting the sequence (adding the edges to the graph) depends on the alignment type of the object. The pass SetSequence adds the edges to the graph according to the alignment type.

For parallel alignment, a mapping of PulseTarget and Frame to MixedFrames is needed. For this purpose, an analysis pass MapMixedFrame is also added. The pass recurses through the IR, and identifies creates the mapping.

@TsafrirA TsafrirA requested review from eggerdj, wshanks and a team as code owners March 9, 2024 22:56
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @nkanazawa1989

@TsafrirA TsafrirA added mod: pulse Related to the Pulse module experimental Experimental feature without API stability guarantee labels Mar 9, 2024
pm.append(SetSequence())
return pm

@named_data(*ddt_named_data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested everything against all relevant alignment types. It's kind of an overkill, with the logic located at a parent abstract class.

Copy link
Contributor

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @TsafrirA . The sequence logic looks good to me. My main concern is about implementation of sequence pass, and I think the sequence logic must be implemented inside the pass, rather than delegating it to the alignment object.

Here is another question. When we talk to a hardware, I think they request mixed frames. However, in the current implementation, broadcast is not really implemented. Instead, the sequence pass just create edges to a common node to broadcast. Do you want to write a separate pass for broadcast? We can also do this broadcast inside the sequencing pass with slight modification.

Comment on lines 43 to 44
self._analyze_mixed_frames_in_sequence(passmanager_ir)
self.property_set["mixed_frames_mapping"] = self.mixed_frames_mapping
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._analyze_mixed_frames_in_sequence(passmanager_ir)
self.property_set["mixed_frames_mapping"] = self.mixed_frames_mapping
mixed_frames_mapping = defaultdict(set)
self._analyze_mixed_frames_in_sequence(passmanager_ir, mixed_frames_mapping)
self.property_set["mixed_frames_mapping"] = mixed_frames_mapping

Can we implement the logic like this? Statefull pass sometimes causes edge cases. For example, in the current implementation some unexpected things could happen if you run the same pass manager instance twice for different inputs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue of re-running a pass is something that bothered me too. Do we override existing data? Raise an error? There's a "global" decision to be made here, because it's applicable to all passes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the current pass, I modified it per your suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is definitely a demand for rerunning the pass manager, for example #11784. I prefer pass that doesn't have state, except for the user provided arguments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, should we remove all edges from the sequence before sequencing?

qiskit/pulse/compiler/passes/map_mixed_frames.py Outdated Show resolved Hide resolved
qiskit/pulse/compiler/passes/map_mixed_frames.py Outdated Show resolved Hide resolved

def __init__(self):
"""Create new MapMixedFrames pass"""
super().__init__(target=None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates typehint (though type is not important in Python). Do you want to remove Target from the base passes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I commented on the original compiler PR, we don't always need Target. I think we can make it optional.

test/python/pulse/compiler_passes/test_set_sequence.py Outdated Show resolved Hide resolved
test/python/pulse/compiler_passes/test_set_sequence.py Outdated Show resolved Hide resolved
test/python/pulse/compiler_passes/utils.py Outdated Show resolved Hide resolved
@nkanazawa1989 nkanazawa1989 linked an issue Mar 11, 2024 that may be closed by this pull request
9 tasks
@nkanazawa1989 nkanazawa1989 mentioned this pull request Mar 11, 2024
9 tasks
Copy link
Contributor

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it looks almost good to go. Just a few minor comments before approval.

qiskit/pulse/compiler/passes/set_sequence.py Outdated Show resolved Hide resolved
test/python/pulse/compiler_passes/test_set_sequence.py Outdated Show resolved Hide resolved
test/python/pulse/compiler_passes/utils.py Outdated Show resolved Hide resolved
Copy link
Contributor

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks @TsafrirA

@nkanazawa1989 nkanazawa1989 merged commit 8213ff3 into Qiskit:feature/pulse-ir Mar 12, 2024
10 checks passed
@TsafrirA TsafrirA deleted the SequencePass branch March 13, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental Experimental feature without API stability guarantee mod: pulse Related to the Pulse module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pulse Compiler and IR
3 participants