Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add measurement gate #41

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/py/examples/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
c.add(gates.Y(), [4])
c.add(gates.X(), [4, 1])
c.add(gates.X(), [0])
c.add(gates.M(), [1])
c.add(gates.M(), [3])
c.add(gates.M(), [4])

print(c)

Expand Down
148 changes: 0 additions & 148 deletions crates/py/qibo_core/measurements.py

This file was deleted.

10 changes: 6 additions & 4 deletions crates/py/qibo_core/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import numpy as np

from . import einsum_utils
from .qibo_core import gate
from .npmatrices import NumpyMatrices
from .result import CircuitResult, MeasurementOutcomes, QuantumState
from .config import SHOT_BATCH_SIZE

gates = gate.Gate

class NumpyBackend:
def __init__(self):
Expand Down Expand Up @@ -416,12 +418,12 @@ def execute_circuit(
state = self.cast(initial_state)

for gate, elements in circuit:
# TODO: Handle measurements and ``CallbackGate``
state = self.apply_gate(gate, elements, state, nqubits)
if not isinstance(gate, gates.M):
state = self.apply_gate(gate, elements, state, nqubits)

if len(circuit.measurements) > 0:
if len(circuit.measured_elements) > 0:
return CircuitResult(
state, circuit.measurements, backend=self, nshots=nshots
state, circuit.measured_elements, nshots=nshots, backend=self,
)
return QuantumState(state, backend=self)

Expand Down
Loading