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

Coverage fix #1288

Merged
merged 19 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b33472a
fix: trying to improve coverage
BrunoLiegiBastonLiegi Mar 28, 2024
2392663
fix: fixed the noisy gate
BrunoLiegiBastonLiegi Mar 28, 2024
02c4a01
fix: fixed pauli noise channel init type check
BrunoLiegiBastonLiegi Mar 28, 2024
86bcc82
Revert "fix: fixed pauli noise channel init type check"
BrunoLiegiBastonLiegi Mar 29, 2024
b50872d
fix: removed unneeded measurement reset
BrunoLiegiBastonLiegi Mar 29, 2024
75bbd57
fix: restored old target frequencies
BrunoLiegiBastonLiegi Mar 29, 2024
ba2f2e9
cov: added test to improve coverage of result.py
BrunoLiegiBastonLiegi Mar 30, 2024
7eb1ee0
Merge branch 'master' into cov_fix
BrunoLiegiBastonLiegi May 22, 2024
d1a17fd
Merge branch 'master' into cov_fix
BrunoLiegiBastonLiegi Jun 3, 2024
38bb7e7
Merge branch 'master' into cov_fix
BrunoLiegiBastonLiegi Jul 3, 2024
4a6fe3a
test: added test for symbols pickling
BrunoLiegiBastonLiegi Jul 3, 2024
b819b7d
test: added test for measurmentsymbol pickling
BrunoLiegiBastonLiegi Jul 3, 2024
21c766e
feat: commented register_name check
BrunoLiegiBastonLiegi Jul 4, 2024
cb74336
Merge branch 'master' into cov_fix
BrunoLiegiBastonLiegi Jul 5, 2024
ff57403
fix: removed commented lines
BrunoLiegiBastonLiegi Jul 5, 2024
eb11b8c
Merge branch 'master' into cov_fix
renatomello Jul 12, 2024
cfde704
Update tests/test_hamiltonians_from_symbols.py
renatomello Jul 12, 2024
c9900fe
updated lock
renatomello Jul 12, 2024
6be8f28
Merge branch 'cov_fix' of github.com:qiboteam/qibo into cov_fix
renatomello Jul 12, 2024
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
758 changes: 406 additions & 352 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/qibo/gates/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ def raw(self) -> dict:
if key in REQUIRED_FIELDS_INIT_KWARGS
}

for value in encoded_simple:
if isinstance(encoded[value], set):
encoded_simple[value] = list(encoded_simple[value])

encoded_simple["_class"] = type(self).__name__

return encoded_simple
Expand Down
8 changes: 1 addition & 7 deletions src/qibo/models/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,7 @@ def add(self, gate):
@property
def measurement_tuples(self):
# used for testing only
registers = {}
for m in self.measurements:
if m.register_name not in registers:
registers[m.register_name] = m.target_qubits
else:
registers[m.register_name] += m.target_qubits
return {name: qubits for name, qubits in registers.items()}
return {m.register_name: m.target_qubits for m in self.measurements}

@property
def ngates(self) -> int:
Expand Down
3 changes: 0 additions & 3 deletions src/qibo/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ def __init__(
for m in measurements:
indices = [self.measurement_gate.qubits.index(q) for q in m.qubits]
m.result.register_samples(samples[:, indices])
else:
for gate in self.measurements:
gate.result.reset()

def frequencies(self, binary: bool = True, registers: bool = False):
"""Returns the frequencies of measured samples.
Expand Down
10 changes: 6 additions & 4 deletions tests/test_backends_clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,15 @@ def test_noise_channels(backend, seed):
clifford_bkd = construct_clifford_backend(backend)
clifford_bkd.set_seed(seed)

noise = NoiseModel()
noise.add(PauliError([("X", 0.5)]), gates.X)
noise.add(DepolarizingError(0.1), gates.CZ)

nqubits = 3

c = random_clifford(nqubits, density_matrix=True, seed=seed, backend=backend)

noise = NoiseModel()
noisy_gates = np.random.choice(c.queue, size=1, replace=False)
noise.add(PauliError([("X", 0.3)]), gates.H)
noise.add(DepolarizingError(0.3), noisy_gates[0].__class__)

c.add(gates.M(*range(nqubits)))
c_copy = c.copy()

Expand Down
13 changes: 13 additions & 0 deletions tests/test_hamiltonians_from_symbols.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test dense matrix of Hamiltonians constructed using symbols."""

import pickle

import numpy as np
import pytest
import sympy
Expand All @@ -10,6 +12,17 @@
from qibo.symbols import I, Symbol, X, Y, Z


@pytest.mark.parametrize("symbol", [I, X, Y, Z])
def test_symbols_pickling(symbol):
symbol = symbol(int(np.random.randint(4)))
dumped_symbol = pickle.dumps(symbol)
new_symbol = pickle.loads(dumped_symbol)
for attr in ("target_qubit", "name", "_gate"):
print(attr)
renatomello marked this conversation as resolved.
Show resolved Hide resolved
assert getattr(symbol, attr) == getattr(new_symbol, attr)
np.testing.assert_allclose(symbol.matrix, new_symbol.matrix)


@pytest.mark.parametrize("nqubits", [4, 5])
@pytest.mark.parametrize("hamtype", ["normal", "symbolic"])
@pytest.mark.parametrize("calcterms", [False, True])
Expand Down
16 changes: 16 additions & 0 deletions tests/test_measurements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test circuit result measurements and measurement gate and as part of circuit."""

import pickle

import numpy as np
import pytest

Expand Down Expand Up @@ -457,3 +459,17 @@ def test_measurement_same_qubit_different_registers_error(backend):
c.add(gates.M(0, 1, 3, register_name="a"))
with pytest.raises(KeyError):
c.add(gates.M(1, 2, 3, register_name="a"))


def test_measurementsymbol_pickling(backend):
from qibo.models import QFT

c = QFT(3)
c.add(gates.M(0, 2, basis=[gates.X, gates.Z]))
backend.execute_circuit(c).samples()
for symbol in c.measurements[0].result.symbols:
dumped_symbol = pickle.dumps(symbol)
new_symbol = pickle.loads(dumped_symbol)
assert symbol.index == new_symbol.index
assert symbol.name == new_symbol.name
backend.assert_allclose(symbol.result.samples(), new_symbol.result.samples())
10 changes: 10 additions & 0 deletions tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def test_measurementoutcomes_probabilities(backend, qubits):
backend.assert_allclose(result.probabilities(qubits), probabilities, atol=1e-1)


def test_measurementoutcomes_samples_from_measurements(backend):
c = Circuit(3)
c.add(gates.H(0))
c.add(gates.M(0, 2))
res = backend.execute_circuit(c)
samples = res.samples()
outcome = MeasurementOutcomes(c.measurements, backend=backend)
backend.assert_allclose(samples, outcome.samples())


def test_circuit_result_error(backend):
c = models.Circuit(1)
state = np.array([1, 0])
Expand Down
Loading