Skip to content

Commit

Permalink
native pragma support
Browse files Browse the repository at this point in the history
  • Loading branch information
notmgsk committed Dec 7, 2020
1 parent 2ceb0ac commit ddfda7a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions pyquil/pragmas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
##############################################################################
# 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


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):
def __init__(self, instructions: Iterable[AbstractInstruction]):
self.instructions = 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"

0 comments on commit ddfda7a

Please sign in to comment.