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

Bugfix/support create #90

Merged
merged 2 commits into from
Mar 29, 2024
Merged
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
4 changes: 2 additions & 2 deletions pytket/extensions/cutensornet/tensor_network_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _assign_node_tensors(self, adj: bool = False) -> List[Any]:
self._input_nodes = []
self._output_nodes = []
for i, node in reversed(list(enumerate(self._network.nodes(data=True)))):
if node[1]["desc"] not in ("Input", "Output"):
if node[1]["desc"] not in ("Input", "Output", "Create"):
n_out_edges = len(list(self._network.out_edges(node[0])))
if n_out_edges > 1:
src_ports = [
Expand Down Expand Up @@ -213,7 +213,7 @@ def _assign_node_tensors(self, adj: bool = False) -> List[Any]:
else:
if node[1]["desc"] == "Output":
self._output_nodes.append(i)
if node[1]["desc"] == "Input":
if node[1]["desc"] == "Input" or node[1]["desc"] == "Create":
self._input_nodes.append(i)
node_tensors.append(np.array([1, 0], dtype="complex128"))
if adj:
Expand Down
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,24 @@ def q4_multicontrols() -> Circuit:
return circ


@pytest.fixture
def q4_with_creates() -> Circuit:
circuit = Circuit(4)
circuit.qubit_create_all()

circuit.S(1)
circuit.Rz(0.3, 0)
circuit.Ry(0.1, 2)
circuit.TK1(0.2, 0.9, 0.8, 3)
circuit.TK2(0.6, 0.5, 0.7, 1, 2)
circuit.X(0)
circuit.H(2)
circuit.V(1)
circuit.Z(3)

return circuit


@pytest.fixture
def q5_h0s1rz2ry3tk4tk13() -> Circuit:
circuit = Circuit(5)
Expand Down
1 change: 1 addition & 0 deletions tests/test_cutensornet_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def test_expectation_value() -> None:
pytest.lazy_fixture("q3_cx01cz12x1rx0"), # type: ignore
pytest.lazy_fixture("q4_lcu1"), # type: ignore
pytest.lazy_fixture("q4_multicontrols"), # type: ignore
pytest.lazy_fixture("q4_with_creates"), # type: ignore
],
)
def test_compile_convert_statevec_overlap(circuit: Circuit) -> None:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_structured_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def test_canonicalise_ttn(center: Union[RootPath, Qubit]) -> None:
pytest.lazy_fixture("q2_lcu3"), # type: ignore
pytest.lazy_fixture("q3_v0cx02"), # type: ignore
pytest.lazy_fixture("q3_cx01cz12x1rx0"), # type: ignore
pytest.lazy_fixture("q4_with_creates"), # type: ignore
pytest.lazy_fixture("q5_h0s1rz2ry3tk4tk13"), # type: ignore
pytest.lazy_fixture("q5_line_circ_30_layers"), # type: ignore
pytest.lazy_fixture("q6_qvol"), # type: ignore
Expand Down Expand Up @@ -286,6 +287,7 @@ def test_exact_circ_sim(circuit: Circuit, algorithm: SimulationAlgorithm) -> Non
pytest.lazy_fixture("q2_lcu3"), # type: ignore
pytest.lazy_fixture("q3_v0cx02"), # type: ignore
pytest.lazy_fixture("q3_cx01cz12x1rx0"), # type: ignore
pytest.lazy_fixture("q4_with_creates"), # type: ignore
pytest.lazy_fixture("q5_h0s1rz2ry3tk4tk13"), # type: ignore
pytest.lazy_fixture("q5_line_circ_30_layers"), # type: ignore
pytest.lazy_fixture("q6_qvol"), # type: ignore
Expand Down Expand Up @@ -333,6 +335,7 @@ def test_approx_circ_sim_gate_fid(
pytest.lazy_fixture("q2_lcu3"), # type: ignore
pytest.lazy_fixture("q3_v0cx02"), # type: ignore
pytest.lazy_fixture("q3_cx01cz12x1rx0"), # type: ignore
pytest.lazy_fixture("q4_with_creates"), # type: ignore
pytest.lazy_fixture("q5_h0s1rz2ry3tk4tk13"), # type: ignore
pytest.lazy_fixture("q5_line_circ_30_layers"), # type: ignore
pytest.lazy_fixture("q6_qvol"), # type: ignore
Expand Down Expand Up @@ -366,6 +369,7 @@ def test_approx_circ_sim_chi(circuit: Circuit, algorithm: SimulationAlgorithm) -
pytest.lazy_fixture("q2_x0cx01cx10"), # type: ignore
pytest.lazy_fixture("q2_lcu2"), # type: ignore
pytest.lazy_fixture("q3_cx01cz12x1rx0"), # type: ignore
pytest.lazy_fixture("q4_with_creates"), # type: ignore
pytest.lazy_fixture("q5_line_circ_30_layers"), # type: ignore
pytest.lazy_fixture("q6_qvol"), # type: ignore
],
Expand Down Expand Up @@ -585,6 +589,7 @@ def test_postselect_circ(circuit: Circuit, postselect_dict: dict) -> None:
pytest.lazy_fixture("q2_lcu2"), # type: ignore
pytest.lazy_fixture("q2_lcu3"), # type: ignore
pytest.lazy_fixture("q3_cx01cz12x1rx0"), # type: ignore
pytest.lazy_fixture("q4_with_creates"), # type: ignore
pytest.lazy_fixture("q5_line_circ_30_layers"), # type: ignore
],
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_tensor_network_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def circuit_overlap_contract(circuit_ket: Circuit) -> float:
pytest.lazy_fixture("q3_cx01cz12x1rx0"), # type: ignore
pytest.lazy_fixture("q4_lcu1"), # type: ignore
pytest.lazy_fixture("q4_multicontrols"), # type: ignore
pytest.lazy_fixture("q4_with_creates"), # type: ignore
],
)
def test_convert_statevec_overlap(circuit: Circuit) -> None:
Expand Down