Skip to content

Commit ddfda7a

Browse files
committed
native pragma support
1 parent 2ceb0ac commit ddfda7a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

pyquil/pragmas.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
##############################################################################
2+
# Copyright 2016-2018 Rigetti Computing
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
##############################################################################
16+
17+
from typing import List, Iterable
18+
19+
from pyquil.quilbase import AbstractInstruction, Pragma
20+
21+
22+
class InitialRewiring(Pragma):
23+
def __init__(self, rewiring: str):
24+
self.rewiring = rewiring
25+
26+
def out(self) -> str:
27+
return f'PRAGMA INITIAL_REWIRING "{self.rewiring}"'
28+
29+
30+
NAIVE_REWIRING = InitialRewiring("NAIVE")
31+
RANDOM_REWIRING = InitialRewiring("RANDOM")
32+
GREEDY_REWIRING = InitialRewiring("GREEDY")
33+
PARTIAL_REWIRING = InitialRewiring("PARTIAL")
34+
35+
36+
class PreserveBlock(Pragma):
37+
def __init__(self, instructions: Iterable[AbstractInstruction]):
38+
self.instructions = instructions
39+
40+
def out(self) -> str:
41+
return "PRAGMA PRESERVE_BLOCK\n{}\nPRAGMA END_PRESERVE_BLOCK".format(
42+
"\n".join([str(instr) for instr in self.instructions]),
43+
)
44+
45+
46+
class CommutingBlocks(Pragma):
47+
def __init__(self, blocks: List[Iterable[AbstractInstruction]]):
48+
self.blocks = blocks
49+
50+
def out(self) -> str:
51+
blocks = "\n".join([f"PRAGMA BLOCK\n{block}PRAGMA END_BLOCK" for block in self.blocks])
52+
return f"PRAGMA COMMUTING_BLOCKS\n{blocks}\nPRAGMA END_COMMUTING_BLOCKS"

0 commit comments

Comments
 (0)