|
13 | 13 | import pytest |
14 | 14 |
|
15 | 15 | from graphix.command import E |
16 | | -from graphix.fundamentals import Plane |
| 16 | +from graphix.fundamentals import Axis, Plane |
17 | 17 | from graphix.measurements import Measurement |
18 | 18 | from graphix.opengraph import OpenGraph, OpenGraphError |
19 | 19 | from graphix.pattern import Pattern |
@@ -633,8 +633,101 @@ def test_from_to_pattern(self, fx_rng: Generator) -> None: |
633 | 633 | state = pattern.simulate_pattern(input_state=PlanarState(plane, alpha)) |
634 | 634 | assert np.abs(np.dot(state.flatten().conjugate(), state_ref.flatten())) == pytest.approx(1) |
635 | 635 |
|
| 636 | + def test_isclose_measurement(self) -> None: |
| 637 | + og_1 = OpenGraph( |
| 638 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 639 | + input_nodes=[0], |
| 640 | + output_nodes=[3], |
| 641 | + measurements=dict.fromkeys(range(3), Measurement(0.1, Plane.XY)), |
| 642 | + ) |
| 643 | + og_2 = OpenGraph( |
| 644 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 645 | + input_nodes=[0], |
| 646 | + output_nodes=[3], |
| 647 | + measurements=dict.fromkeys(range(3), Measurement(0.15, Plane.XY)), |
| 648 | + ) |
| 649 | + og_3 = OpenGraph( |
| 650 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3), (0, 3)]), |
| 651 | + input_nodes=[0], |
| 652 | + output_nodes=[3], |
| 653 | + measurements=dict.fromkeys(range(3), Measurement(0.15, Plane.XY)), |
| 654 | + ) |
| 655 | + assert og_1.isclose(og_2, abs_tol=0.1) |
| 656 | + assert not og_1.isclose(og_2) |
| 657 | + assert not og_2.isclose(og_3) |
| 658 | + |
| 659 | + def test_isclose_plane(self) -> None: |
| 660 | + og_1 = OpenGraph( |
| 661 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 662 | + input_nodes=[0], |
| 663 | + output_nodes=[3], |
| 664 | + measurements=dict.fromkeys(range(3), Plane.XY), |
| 665 | + ) |
| 666 | + og_2 = OpenGraph( |
| 667 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 668 | + input_nodes=[0], |
| 669 | + output_nodes=[3], |
| 670 | + measurements=dict.fromkeys(range(3), Plane.XZ), |
| 671 | + ) |
| 672 | + |
| 673 | + assert not og_1.isclose(og_2) |
| 674 | + assert og_1.isclose(og_1) |
| 675 | + |
| 676 | + def test_isclose_axis(self) -> None: |
| 677 | + og_1 = OpenGraph( |
| 678 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 679 | + input_nodes=[0], |
| 680 | + output_nodes=[3], |
| 681 | + measurements=dict.fromkeys(range(3), Axis.X), |
| 682 | + ) |
| 683 | + og_2 = OpenGraph( |
| 684 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 685 | + input_nodes=[0], |
| 686 | + output_nodes=[3], |
| 687 | + measurements=dict.fromkeys(range(3), Axis.Y), |
| 688 | + ) |
| 689 | + |
| 690 | + assert not og_1.isclose(og_2) |
| 691 | + assert og_1.isclose(og_1) |
| 692 | + assert og_2.isclose(og_2) |
| 693 | + |
| 694 | + def test_is_equal_structurally(self) -> None: |
| 695 | + og_1 = OpenGraph( |
| 696 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 697 | + input_nodes=[0], |
| 698 | + output_nodes=[3], |
| 699 | + measurements=dict.fromkeys(range(3), Measurement(0.15, Plane.XY)), |
| 700 | + ) |
| 701 | + og_2 = OpenGraph( |
| 702 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 703 | + input_nodes=[0], |
| 704 | + output_nodes=[3], |
| 705 | + measurements=dict.fromkeys(range(3), Measurement(0.1, Plane.XY)), |
| 706 | + ) |
| 707 | + og_3 = OpenGraph( |
| 708 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 709 | + input_nodes=[0], |
| 710 | + output_nodes=[3], |
| 711 | + measurements=dict.fromkeys(range(3), Plane.XY), |
| 712 | + ) |
| 713 | + og_4 = OpenGraph( |
| 714 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3)]), |
| 715 | + input_nodes=[0], |
| 716 | + output_nodes=[3], |
| 717 | + measurements=dict.fromkeys(range(3), Axis.X), |
| 718 | + ) |
| 719 | + og_5 = OpenGraph( |
| 720 | + graph=nx.Graph([(0, 1), (1, 2), (2, 3), (0, 3)]), |
| 721 | + input_nodes=[0], |
| 722 | + output_nodes=[3], |
| 723 | + measurements=dict.fromkeys(range(3), Axis.X), |
| 724 | + ) |
| 725 | + assert og_1.is_equal_structurally(og_2) |
| 726 | + assert og_1.is_equal_structurally(og_3) |
| 727 | + assert og_1.is_equal_structurally(og_4) |
| 728 | + assert not og_1.is_equal_structurally(og_5) |
| 729 | + |
636 | 730 |
|
637 | | -# TODO: Add test `OpenGraph.is_close` |
638 | 731 | # TODO: rewrite as parametric tests |
639 | 732 |
|
640 | 733 | # Tests composition of two graphs |
|
0 commit comments