feat(core): implement Circuit.append with corresponding unit tests (#59)#65
Conversation
|
Hi @rafaelha, this is my first time contributing to this repo. Could you take a look at this PR and share your feedback. Thanks! |
|
Hi this looks good, but a few things are still missing. It's best to look at the In your current PR, Tsim also unrolls all loops. So, when you add a @overload
def append(
self,
name: str,
targets: Union[int, stim.GateTarget, stim.PauliString, Iterable[Union[int, stim.GateTarget, stim.PauliString]]],
arg: Union[float, Iterable[float]],
*,
tag: str = "",
) -> None:
pass
@overload
def append(
self,
name: Union[stim.CircuitInstruction, stim.CircuitRepeatBlock, stim.Circuit],
) -> None:
pass
def append(
self,
name: object,
targets: object = (),
arg: object = None,
*,
tag: str = '',
) -> None: |
|
Finally, could you also reuse the Stim docstring for """Appends an operation into the circuit.
Args:
name: The name of the operation's gate (e.g. "H" or "M" or "CNOT").
This argument can also be set to a `stim.CircuitInstruction` or
`stim.CircuitInstructionBlock`, which results in the instruction or
block being appended to the circuit. The other arguments (targets
and arg) can't be specified when doing so.
targets: The objects operated on by the gate. This can be either a
single target or an iterable of multiple targets.
Each target can be:
An int: The index of a targeted qubit.
A `stim.GateTarget`: Could be a variety of things. Methods like
`stim.target_rec`, `stim.target_sweet`, `stim.target_x`, and
`stim.CircuitInstruction.__getitem__` all return this type.
A `stim.PauliString`: This will automatically be expanded into
a product of pauli targets like `X1*Y2*Z3`.
arg: The "parens arguments" for the gate, such as the probability for a
noise operation. A double or list of doubles parameterizing the
gate. Different gates take different parens arguments. For example,
X_ERROR takes a probability, OBSERVABLE_INCLUDE takes an observable
index, and PAULI_CHANNEL_1 takes three disjoint probabilities.
tag: A customizable string attached to the instruction.
""" |
|
Hi @rafaelha, I think I’ve incorporated all the suggestions. Could you take a look at the latest commit? |
rafaelha
left a comment
There was a problem hiding this comment.
This looks great! Thanks for the contribution!
Changes Made
src/tsim/circuit.py, drafted theappendfunction which detects the operation name."T"and"T_DAG"mappings to.append("S" / "S_DAG", tag="T")."R_X","R_Y","R_Z", and"U3"inputs toIgates configured with string-interpolated tags holding their calculated parameters, formatted similarly to:.append("I", arg=(), tag="R_Z(theta=0.3*pi)")appendparameters, preserving its flexibility.test/unit/test_circuit.pyto validate behavior; all tests passed successfully viapytest.