Skip to content

Commit

Permalink
Merge branch 'master' into clifford_simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Dec 11, 2023
2 parents 5aac466 + c2c815a commit 3149c91
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ dmypy.json

# tmp files
tmp/
tmp.npy

# Mac
.DS_Store
Expand Down
9 changes: 9 additions & 0 deletions src/qibo/gates/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ def to_pauli_liouville(

return super_op

def matrix(self, backend=None):
""""""
raise_error(
NotImplementedError,
"`matrix` method not defined for Channels. "
+ "Please use one of the following methods: "
+ "`to_choi` or `to_liouville` or `to_pauli_liouville`.",
)


class KrausChannel(Channel):
"""General channel defined by arbitrary Kraus operators.
Expand Down
5 changes: 3 additions & 2 deletions src/qibo/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ def state(self, numpy: bool = False):
"""State's tensor representation as a backend tensor.
Args:
numpy (bool, optional): If ``True`` the returned tensor will be a numpy array,
numpy (bool, optional): If ``True`` the returned tensor will be a ``numpy`` array,
otherwise it will follow the backend tensor type.
Defaults to ``False``.
Returns:
The state in the computational basis.
"""
if numpy:
return np.array(self._state)
return np.array(self._state.tolist())

return self._state

def probabilities(self, qubits: Optional[Union[list, set]] = None):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_gates_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def test_general_channel(backend):
with pytest.raises(NotImplementedError):
state = random_statevector(2**2, backend=backend)
channel1.apply(backend, state, 2)
with pytest.raises(NotImplementedError):
channel1.matrix(backend)


def test_controlled_by_channel_error():
Expand Down

0 comments on commit 3149c91

Please sign in to comment.