-
Notifications
You must be signed in to change notification settings - Fork 342
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
Native pragma support #1282
base: master
Are you sure you want to change the base?
Native pragma support #1282
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
############################################################################## | ||
# Copyright 2016-2018 Rigetti Computing | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
############################################################################## | ||
|
||
from typing import List, Iterable | ||
|
||
from pyquil.quilbase import AbstractInstruction, Pragma | ||
from pyquil.quil import Program | ||
|
||
|
||
class InitialRewiring(Pragma): | ||
def __init__(self, rewiring: str): | ||
self.rewiring = rewiring | ||
|
||
def out(self) -> str: | ||
return f'PRAGMA INITIAL_REWIRING "{self.rewiring}"' | ||
|
||
|
||
NAIVE_REWIRING = InitialRewiring("NAIVE") | ||
RANDOM_REWIRING = InitialRewiring("RANDOM") | ||
GREEDY_REWIRING = InitialRewiring("GREEDY") | ||
PARTIAL_REWIRING = InitialRewiring("PARTIAL") | ||
|
||
|
||
class PreserveBlock(Pragma): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this get tricky? Since it wraps the instructions, it might introduce cases where code that assumed Might be simpler to just vend the pragmas for block start and end separately? |
||
def __init__(self, *instructions: Iterable[AbstractInstruction]): | ||
self.instructions = Program(instructions) | ||
|
||
def out(self) -> str: | ||
return "PRAGMA PRESERVE_BLOCK\n{}\nPRAGMA END_PRESERVE_BLOCK".format( | ||
"\n".join([str(instr) for instr in self.instructions]), | ||
) | ||
|
||
|
||
class CommutingBlocks(Pragma): | ||
def __init__(self, blocks: List[Iterable[AbstractInstruction]]): | ||
self.blocks = blocks | ||
|
||
def out(self) -> str: | ||
blocks = "\n".join([f"PRAGMA BLOCK\n{block}PRAGMA END_BLOCK" for block in self.blocks]) | ||
return f"PRAGMA COMMUTING_BLOCKS\n{blocks}\nPRAGMA END_COMMUTING_BLOCKS" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A thought - what about making this an enum to group them together?
Then the enum also becomes documentation of what the available options are.