Skip to content

Circuits always measure all qubits #189

@vbelis

Description

@vbelis

Describe the bug
It seems that the circuits are always compiled to qiskit.QuantumCircuit with measurements on all qubits. This can be checked in the definition of registers:

self._creg = ClassicalRegister(self.num_wires, "c")
and appending measurements:
measure(self._circuit, qr, cr)

To Reproduce
A simplified example that demonstrates the behavior (i.e. measuring all qubits) of the source code referenced above is the following.

import pennylane as pnl

qdev_hardware = pnl.device(
    "qiskit.ibmq",
    wires=4,
    backend="ibmq_bogota",
    ibmqx_token=private_api_token,
    )

@pnl.qnode(qdev_hardware)
def circuit(params):
    pnl.RX(params[0], wires=0)
    pnl.RY(params[1], wires=1)
    return pnl.expval(pnl.PauliZ(0))

print(circuit([0.54,0.1]))

My goal is to train a variational classifier on an real hardware IBMQ backend. Using a quantum circuit function, implemented in pennylanewith the return value: pennylane.expval(pnl.PauliZ(0)) the transpiled circuit that appears under the corresponding job in IBMQ has measurements on all qubits (see screenshot section below).

Expected behavior
To transpile and send a circuit to the IBMQ backend with the same measurement operator as the one defined in the pennylane circuit function.

Screenshots
Example of IBMQ backend transpiled circuit job generated by the above code snippet:
image

Environment

  • Python version: 3.9.7
  • OS : Red Hat 7.9
  • Versions: qiskit==0.34.2, pennylane==0.20.0, pennylane-qiskit==0.21.0

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions