@@ -82,6 +82,7 @@ API references for stable versions are kept on the [stim github wiki](https://gi
8282 - [ ` stim.CircuitInstruction.gate_args_copy ` ] ( #stim.CircuitInstruction.gate_args_copy )
8383 - [ ` stim.CircuitInstruction.name ` ] ( #stim.CircuitInstruction.name )
8484 - [ ` stim.CircuitInstruction.num_measurements ` ] ( #stim.CircuitInstruction.num_measurements )
85+ - [ ` stim.CircuitInstruction.target_groups ` ] ( #stim.CircuitInstruction.target_groups )
8586 - [ ` stim.CircuitInstruction.targets_copy ` ] ( #stim.CircuitInstruction.targets_copy )
8687- [ ` stim.CircuitRepeatBlock ` ] ( #stim.CircuitRepeatBlock )
8788 - [ ` stim.CircuitRepeatBlock.__eq__ ` ] ( #stim.CircuitRepeatBlock.__eq__ )
@@ -123,6 +124,7 @@ API references for stable versions are kept on the [stim github wiki](https://gi
123124 - [ ` stim.DemInstruction.__repr__ ` ] ( #stim.DemInstruction.__repr__ )
124125 - [ ` stim.DemInstruction.__str__ ` ] ( #stim.DemInstruction.__str__ )
125126 - [ ` stim.DemInstruction.args_copy ` ] ( #stim.DemInstruction.args_copy )
127+ - [ ` stim.DemInstruction.target_groups ` ] ( #stim.DemInstruction.target_groups )
126128 - [ ` stim.DemInstruction.targets_copy ` ] ( #stim.DemInstruction.targets_copy )
127129 - [ ` stim.DemInstruction.type ` ] ( #stim.DemInstruction.type )
128130- [ ` stim.DemRepeatBlock ` ] ( #stim.DemRepeatBlock )
@@ -3664,6 +3666,25 @@ def instruction_targets(
36643666 """ Within the error instruction, which may have hundreds of
36653667 targets, which specific targets were being executed to
36663668 produce the error.
3669+
3670+ Examples:
3671+ >>> import stim
3672+ >>> err = stim.Circuit('''
3673+ ... R 0
3674+ ... TICK
3675+ ... Y_ERROR(0.125) 0
3676+ ... M 0
3677+ ... OBSERVABLE_INCLUDE(0) rec[-1]
3678+ ... ''').shortest_graphlike_error()
3679+ >>> targets = err[0].circuit_error_locations[0].instruction_targets
3680+ >>> targets == stim.CircuitTargetsInsideInstruction(
3681+ ... gate='Y_ERROR',
3682+ ... args=[0.125],
3683+ ... target_range_start=0,
3684+ ... target_range_end=1,
3685+ ... targets_in_range=(stim.GateTargetWithCoords(0, []),),
3686+ ... )
3687+ True
36673688 """
36683689```
36693690
@@ -3917,6 +3938,17 @@ def gate_args_copy(
39173938 For noisy gates this typically a list of probabilities.
39183939 For OBSERVABLE_INCLUDE it's a singleton list containing the logical observable
39193940 index.
3941+
3942+ Examples:
3943+ >>> import stim
3944+ >>> instruction = stim.CircuitInstruction('X_ERROR', [2, 3], [0.125])
3945+ >>> instruction.gate_args_copy()
3946+ [0.125]
3947+
3948+ >>> instruction.gate_args_copy() == instruction.gate_args_copy()
3949+ True
3950+ >>> instruction.gate_args_copy() is instruction.gate_args_copy()
3951+ False
39203952 """
39213953```
39223954
@@ -3961,6 +3993,52 @@ def num_measurements(
39613993 """
39623994```
39633995
3996+ <a name =" stim.CircuitInstruction.target_groups " ></a >
3997+ ``` python
3998+ # stim.CircuitInstruction.target_groups
3999+
4000+ # (in class stim.CircuitInstruction)
4001+ def target_groups (
4002+ self ,
4003+ ) -> List[List[stim.GateTarget]]:
4004+ """ Splits the instruction's targets into groups depending on the type of gate.
4005+
4006+ Single qubit gates like H get one group per target.
4007+ Two qubit gates like CX get one group per pair of targets.
4008+ Pauli product gates like MPP get one group per combined product.
4009+
4010+ Returns:
4011+ A list of groups of targets.
4012+
4013+ Examples:
4014+ >>> import stim
4015+ >>> for g in stim.Circuit('H 0 1 2')[0].target_groups():
4016+ ... print(repr(g))
4017+ [stim.GateTarget(0)]
4018+ [stim.GateTarget(1)]
4019+ [stim.GateTarget(2)]
4020+
4021+ >>> for g in stim.Circuit('CX 0 1 2 3')[0].target_groups():
4022+ ... print(repr(g))
4023+ [stim.GateTarget(0), stim.GateTarget(1)]
4024+ [stim.GateTarget(2), stim.GateTarget(3)]
4025+
4026+ >>> for g in stim.Circuit('MPP X0*Y1*Z2 X5*X6')[0].target_groups():
4027+ ... print(repr(g))
4028+ [stim.target_x(0), stim.target_y(1), stim.target_z(2)]
4029+ [stim.target_x(5), stim.target_x(6)]
4030+
4031+ >>> for g in stim.Circuit('DETECTOR rec[-1] rec[-2]')[0].target_groups():
4032+ ... print(repr(g))
4033+ [stim.target_rec(-1)]
4034+ [stim.target_rec(-2)]
4035+
4036+ >>> for g in stim.Circuit('CORRELATED_ERROR(0.1) X0 Y1')[0].target_groups():
4037+ ... print(repr(g))
4038+ [stim.target_x(0), stim.target_y(1)]
4039+ """
4040+ ```
4041+
39644042<a name =" stim.CircuitInstruction.targets_copy " ></a >
39654043``` python
39664044# stim.CircuitInstruction.targets_copy
@@ -3970,6 +4048,17 @@ def targets_copy(
39704048 self ,
39714049) -> List[stim.GateTarget]:
39724050 """ Returns a copy of the targets of the instruction.
4051+
4052+ Examples:
4053+ >>> import stim
4054+ >>> instruction = stim.CircuitInstruction('X_ERROR', [2, 3], [0.125])
4055+ >>> instruction.targets_copy()
4056+ [stim.GateTarget(2), stim.GateTarget(3)]
4057+
4058+ >>> instruction.targets_copy() == instruction.targets_copy()
4059+ True
4060+ >>> instruction.targets_copy() is instruction.targets_copy()
4061+ False
39734062 """
39744063```
39754064
@@ -5335,6 +5424,42 @@ def args_copy(
53355424 """
53365425```
53375426
5427+ <a name =" stim.DemInstruction.target_groups " ></a >
5428+ ``` python
5429+ # stim.DemInstruction.target_groups
5430+
5431+ # (in class stim.DemInstruction)
5432+ def target_groups (
5433+ self ,
5434+ ) -> List[List[stim.DemTarget]]:
5435+ """ Returns a copy of the instruction's targets, split by target separators.
5436+
5437+ When a detector error model instruction contains a suggested decomposition,
5438+ its targets contain separators (`stim.DemTarget("^")`). This method splits the
5439+ targets into groups based the separators, similar to how `str.split` works.
5440+
5441+ Returns:
5442+ A list of groups of targets.
5443+
5444+ Examples:
5445+ >>> import stim
5446+ >>> dem = stim.DetectorErrorModel('''
5447+ ... error(0.01) D0 D1 ^ D2
5448+ ... error(0.01) D0 L0
5449+ ... error(0.01)
5450+ ... ''')
5451+
5452+ >>> dem[0].target_groups()
5453+ [[stim.DemTarget('D0'), stim.DemTarget('D1')], [stim.DemTarget('D2')]]
5454+
5455+ >>> dem[1].target_groups()
5456+ [[stim.DemTarget('D0'), stim.DemTarget('L0')]]
5457+
5458+ >>> dem[2].target_groups()
5459+ [[]]
5460+ """
5461+ ```
5462+
53385463<a name =" stim.DemInstruction.targets_copy " ></a >
53395464``` python
53405465# stim.DemInstruction.targets_copy
@@ -8928,7 +9053,7 @@ class GateTarget:
89289053 >>> circuit[0].targets_copy()[0]
89299054 stim.GateTarget(0)
89309055 >>> circuit[0].targets_copy()[1]
8931- stim.GateTarget(stim. target_inv(1) )
9056+ stim.target_inv(1)
89329057 """
89339058```
89349059
0 commit comments