Skip to content

Commit

Permalink
Add Prod observable support (#64)
Browse files Browse the repository at this point in the history
* Add Prod observable support

* update workflow file to include pytest-benchmark
  • Loading branch information
astralcai authored Apr 16, 2024
1 parent edb9ae7 commit 8eea9ef
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest-benchmark
pip install wheel pytest pytest-cov pytest-mock flaky --upgrade
- name: Install Plugin
Expand Down
3 changes: 3 additions & 0 deletions pennylane_qulacs/qulacs_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class QulacsDevice(QubitDevice):
"Identity": "I",
"Hadamard": None,
"Hermitian": None,
"Prod": None,
}

operations = _operation_map.keys()
Expand Down Expand Up @@ -348,6 +349,8 @@ def expval(self, observable, **kwargs):
qulacs_observable = Observable(self.num_wires)
if isinstance(observable.name, list):
observables = [self._observable_map[obs] for obs in observable.name]
elif observable.name == "Prod":
observables = [self._observable_map[obs.name] for obs in observable.operands]
else:
observables = [self._observable_map[observable.name]]

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def init_state():
"""Fixture to create an n-qubit initial state"""

def _init_state(n):
state = np.random.random([2 ** n]) + np.random.random([2 ** n]) * 1j
state = np.random.random([2**n]) + np.random.random([2**n]) * 1j
state /= np.linalg.norm(state)
return state

Expand Down
4 changes: 3 additions & 1 deletion tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def test_qubit_state_vector(self, init_state, state_prep_op, tol):
@pytest.mark.parametrize("state_prep_op", (qml.QubitStateVector, qml.StatePrep))
@pytest.mark.parametrize("device_wires", [3, 4, 5])
@pytest.mark.parametrize("op_wires", [[0], [2], [0, 1], [1, 0], [2, 0]])
def test_qubit_state_vector_on_wires_subset(self, init_state, device_wires, op_wires, state_prep_op, tol):
def test_qubit_state_vector_on_wires_subset(
self, init_state, device_wires, op_wires, state_prep_op, tol
):
"""Test QubitStateVector and StatePrep application on a subset of device wires"""
dev = QulacsDevice(device_wires)
state = init_state(len(op_wires))
Expand Down

0 comments on commit 8eea9ef

Please sign in to comment.