Skip to content

Commit

Permalink
Integrate TransformProgram with QNode (#4404)
Browse files Browse the repository at this point in the history
* Draft structure

* draf exec

* Simple execute

* Update

* More tests

* Update

* Update exec

* Pylint and black

* Update tests

* Update more tests

* More tests

* changelog

* Coverage

* Cover fix

* pylint

* Pylint

* Pylint tests

* proposed changes to transform program integration

* oops

* add to legacy, remove cotransform support

* just transform program call component

* just transform program call component

* no longer support cotransforms, fix _batch_postprocessing

* some more testing

* test null postprocessing function

* docstring, rename batch_slices to slices, black

* Apply suggestions from code review

Co-authored-by: Matthew Silverman <[email protected]>

* integrate transform program with qnode

* adding integration tests

* test modifications

* [skip ci] fiddling

* more testing

* changelog entry

* add to execute, start on testing

* add qml.execute tests

* Update doc/releases/changelog-dev.md

Co-authored-by: Matthew Silverman <[email protected]>

* fix test

---------

Co-authored-by: rmoyard <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
  • Loading branch information
3 people authored and mudit2812 committed Aug 8, 2023
1 parent 2a07c91 commit 572bfbc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ array([False, False])
* Functions added to convert wavefunctions obtained from `PySCF` to a state vector.
[(#4427)](https://github.com/PennyLaneAI/pennylane/pull/4427)

* Transform Programs are now integrated with the `QNode`.
[(#4404)](https://github.com/PennyLaneAI/pennylane/pull/4404)

```
def null_postprocessing(results: qml.typing.ResultBatch) -> qml.typing.Result:
return results[0]
@qml.transforms.core.transform
def scale_shots(tape: qml.tape.QuantumTape, shot_scaling) -> (Tuple[qml.tape.QuantumTape], Callable):
new_shots = tape.shots.total_shots * shot_scaling
new_tape = qml.tape.QuantumScript(tape.operations, tape.measurements, shots=new_shots)
return (new_tape, ), null_postprocessing
dev = qml.devices.experimental.DefaultQubit2()
@partial(scale_shots, shot_scaling=2)
@qml.qnode(dev, interface=None)
def circuit():
return qml.sample(wires=0)
```

>>> circuit(shots=1)
array([False, False])

<h3>Improvements 🛠</h3>

* Wires can now be reused after making a mid-circuit measurement on them.
Expand Down

0 comments on commit 572bfbc

Please sign in to comment.