What kind of circuit optimizations are made under the hood?

For example, consider this circuit:

dev = qml.device('default.qubit', wires=2, shots=10)
@qml.qnode(dev)
def circ(x):
  qml.RX(x, wires=0)
  qml.RX(1.5, wires=0)
  qml.CNOT(wires=[1,0])
  return qml.probs(0)

Will the device combine the two rotation gates into one?
Is there a way to specify if we want the device to optimize the circuit or not?
Will using a qml.Barrier gate prevent optimization?

Hi @ankit27kh! It is up to the device whether optimizations are implemented. The current built-in PennyLane simulators (default.qubit and lightning.qubit) do not, I believe, modify the circuit — they implement every gate as is. However, some devices (especially hardware devices) may transpile before execution.

Note that you can use our compilation transforms if you would like to optimize a circuit before it is sent to the device:

@qml.qnode(dev)
@qml.transforms.merge_rotations()
def circ(x):
    qml.RX(x, wires=0)
    qml.RX(1.5, wires=0)
    qml.CNOT(wires=[1,0])
    return qml.probs(0)

>>> print(qml.draw(circ)(1))
0: ──RX(2.00)─╭X─┤  Probs
1: ───────────╰C─┤       

Hey @josh, I was asking about PennyLane devices. Thanks for the clarification.