amazon-braket / amazon-braket/amazon-braket-sdk-python

Simplify add and remove verbatim box

未关闭
#1,236 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
373
派生
195
平均合并
4 天 15 小时
30 天内合并 PR
8

描述

**Describe the feature you'd like**

Creating a verbatim box needs `target_circuit = Circuit().add_verbatim_box(target_circuit)`, which is the only instruction with this pattern. There is also is no way to easily remove a verbatim box from a circuit, besides creating a new circuit. This is questionable for partial verbatim boxes as well.

**How would this feature be used? Please describe.**

1. Custom or piece-wise compilation
2. Running verbatim on particular simulators (i.e. with noise models)
3. Modifying nativized or previously modified circuits
4. Simplifying creating verbatim circuits

There are a few options:

1. Add self as an argument `target_circuit.add_verbatim_box()`, since it is always implied that we have access to the targeted instructions of interest
2. Simplify the call, potentially to a ; `target_circuit.verbatim()` with a flag for removal, or even to target particular ranges of instruction
3. Add a remove verbatim method, or add a remove flag to a .verbatim method could either (1) remove all verbatim boxes, or (2) remove the k-th box.

**Describe alternatives you've considered**
Current behavior for a single verbatim:
```
new = Circuit()
for ins in target_circuit.instructions:
if "verbatim" not in ins.name.lower():
new.add_instruction(ins)
```
or
```
from braket.circuis.compiler_directives import StartVerbatimBox, EndVerbatimBox
new = Circuit()
for ins in target_circuit.instructions:
if not isinstance(ins, (StartVerbatimBox, EndVerbatimBox)):
new.add_instruction(ins)
```
This is okay for removing all boxes, but it is slightly more complicated if you want to remove only a single box.

**Additional context**
Should require no changes to the existing serialization.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。