|
1 | 1 | import pytest
|
2 | 2 |
|
3 | 3 | import numpy as np
|
4 |
| -import tensorflow as tf |
5 |
| - |
6 |
| -from c3.generator.devices import Crosstalk |
7 |
| -from c3.generator.generator import Generator |
8 |
| -from c3.c3objs import Quantity as Qty |
9 |
| -from c3.parametermap import ParameterMap |
10 |
| - |
11 |
| - |
12 |
| -xtalk = Crosstalk( |
13 |
| - name="crosstalk", |
14 |
| - channels=["TC1", "TC2"], |
15 |
| - crosstalk_matrix=Qty( |
16 |
| - value=[[1, 0], [0, 1]], |
17 |
| - min_val=[[0, 0], [0, 0]], |
18 |
| - max_val=[[1, 1], [1, 1]], |
19 |
| - unit="", |
20 |
| - ), |
21 |
| -) |
22 |
| - |
23 |
| -signal = { |
24 |
| - "TC1": {"values": tf.linspace(0, 100, 101)}, |
25 |
| - "TC2": {"values": tf.linspace(100, 200, 101)}, |
26 |
| -} |
27 |
| - |
28 |
| -gen = Generator(devices={"crosstalk": xtalk}) |
29 |
| -pmap = ParameterMap(generator=gen) |
30 |
| -pmap.set_opt_map([[["crosstalk", "crosstalk_matrix"]]]) |
31 | 4 |
|
32 | 5 |
|
33 | 6 | @pytest.mark.unit
|
34 |
| -def test_crosstalk() -> None: |
35 |
| - new_sig = xtalk.process(signal=signal) |
36 |
| - assert new_sig == signal |
| 7 | +def test_crosstalk(get_xtalk_pmap, get_test_signal) -> None: |
| 8 | + xtalk = get_xtalk_pmap.generator.devices["crosstalk"] |
| 9 | + new_sig = xtalk.process(signal=get_test_signal) |
| 10 | + assert new_sig == get_test_signal |
37 | 11 |
|
38 | 12 |
|
39 | 13 | @pytest.mark.unit
|
40 |
| -def test_crosstalk_flip() -> None: |
| 14 | +def test_crosstalk_flip(get_xtalk_pmap, get_test_signal) -> None: |
| 15 | + xtalk = get_xtalk_pmap.generator.devices["crosstalk"] |
41 | 16 | xtalk.params["crosstalk_matrix"].set_value([[0, 1], [1, 0]])
|
42 |
| - new_sig = xtalk.process(signal=signal) |
| 17 | + new_sig = xtalk.process(signal=get_test_signal) |
43 | 18 | assert (new_sig["TC2"]["values"].numpy() == np.linspace(0, 100, 101)).all()
|
44 | 19 | assert (new_sig["TC1"]["values"].numpy() == np.linspace(100, 200, 101)).all()
|
45 | 20 |
|
46 | 21 |
|
47 | 22 | @pytest.mark.unit
|
48 |
| -def test_crosstalk_mix() -> None: |
| 23 | +def test_crosstalk_mix(get_xtalk_pmap, get_test_signal) -> None: |
| 24 | + xtalk = get_xtalk_pmap.generator.devices["crosstalk"] |
49 | 25 | xtalk.params["crosstalk_matrix"].set_value([[0.5, 0.5], [0.5, 0.5]])
|
50 |
| - new_sig = xtalk.process(signal=signal) |
| 26 | + new_sig = xtalk.process(signal=get_test_signal) |
51 | 27 | assert (new_sig["TC2"]["values"].numpy() == new_sig["TC1"]["values"].numpy()).all()
|
52 | 28 |
|
53 | 29 |
|
54 | 30 | @pytest.mark.unit
|
55 |
| -def test_crosstalk_set_get_parameters() -> None: |
56 |
| - pmap.set_parameters([[1, 1], [1, 1]], [[["crosstalk", "crosstalk_matrix"]]]) |
57 |
| - assert (pmap.get_parameters()[0].get_value().numpy() == [[1, 1], [1, 1]]).all() |
| 31 | +def test_crosstalk_set_get_parameters(get_xtalk_pmap) -> None: |
| 32 | + get_xtalk_pmap.set_parameters( |
| 33 | + [[1, 1], [1, 1]], [[["crosstalk", "crosstalk_matrix"]]] |
| 34 | + ) |
| 35 | + assert ( |
| 36 | + get_xtalk_pmap.get_parameters()[0].get_value().numpy() == [[1, 1], [1, 1]] |
| 37 | + ).all() |
0 commit comments