sandbox-quantum/Tangelo · issue #408 · branch fix/408-simplify-returns-self
Circuit([Gate("H", 0)] * 2).simplify() returned None. The fix touches four methods, not one, because the same pattern was repeated identically across simplify, remove_redundant_gates, remove_small_rotations, and merge_rotations. Two of the four even documented a Returns clause that the implementation never matched. return self on each, plus one focused regression test.
Two consecutive Hadamards cancel out to the identity. Calling .simplify() on that two-gate circuit should leave you with an empty Circuit on the same qubit. Instead it returns None and every subsequent attribute access raises.
circuit.pyEach of the four convenience methods is the same shape:
Two of the four methods (remove_small_rotations, remove_redundant_gates) even have a Returns clause in their docstring: "Returns: Circuit: The circuit without ...". The documentation already promised what the code never delivered.
Adding return self at the end of each method makes the expression form work without changing anything for callers that ignore the return value.
flowchart LR Call["Circuit([H,H]).simplify()"] --> Wrap[method body] Wrap --> Inner[top-level simplify - returns Circuit] Inner --> Splat["self.__dict__ = opt.__dict__
in-place mutation"] Splat -- "before:
(no return)" --> NoneOut["⛔ returns None"] Splat -- "after:
return self" --> SelfOut["✓ returns self (the in-place mutated Circuit)"] style NoneOut fill:#1e0a0a,stroke:#ef4444,color:#fca5a5 style SelfOut fill:#0a1e10,stroke:#10b981,color:#86efac
return self instead of a separate simplified() methodsimplified() / without_redundant_gates() for the read-only form. But that doubles the API surface for every existing pass.self, every popular Python quantum lib (PennyLane's qml.simplify, Qiskit's QuantumCircuit.decompose) does this.c.simplify(); use(c) behave identically.If the SandboxAQ team prefers the split API, the patch is trivial to fold into a simplified() variant, happy to rewrite either way on signal.
The existing test_simplify_circuit (which uses c.simplify(); assert c == ...) continues to pass, in-place behaviour is identical, the new return is just additive.
Local branch fix/408-simplify-returns-self, commit 4e172f3.
Mail to a Tangelo maintainer at SandboxAQ, anchored to the branch URL.
Realistic odds for this lead alone: ~25-40% conversation, ~5-10% contract. SandboxAQ is hiring quantum + AI roles; this is most likely a referral path rather than an immediate retainer.