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

Fix rounding inequalities and allow Makefile to choose between python and python3 #9

Merged
merged 2 commits into from
Sep 27, 2023
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
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
VENV=venv
PYTHON=python

MODULES=qiskit_alice_bob_provider tests
BUILD_DIR=dist
BASE_URL=
API_KEY=
ifeq ($(OS),Windows_NT)
ACTIVATE=$(VENV)/Scripts/activate
PYTHON3_PATH=$(cmd which python3 2> nul)
else
ACTIVATE=$(VENV)/bin/activate
PYTHON3_PATH=$(shell which python3 2> /dev/null)
endif

ifeq ($(PYTHON3_PATH),)
jrj-d marked this conversation as resolved.
Show resolved Hide resolved
PYTHON=python
else
PYTHON=python3
endif

#### Virtual environment
Expand Down
8 changes: 4 additions & 4 deletions qiskit_alice_bob_provider/translation_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ def _substitute_single_qubit_initialize(
elif len(state) == 2 and isinstance(state[0], complex):
global_phase = np.angle(state[0])
state_ph = np.array(state) * np.exp(-1j * global_phase)
if np.array_equal(state_ph, np.array([1, 0])):
if np.allclose(state_ph, np.array([1, 0])):
return Reset()
elif np.array_equal(state_ph, np.array([0, 1])):
elif np.allclose(state_ph, np.array([0, 1])):
return Initialize([0, 1])
elif np.array_equal(state_ph, np.array([1, 1]) / np.sqrt(2)):
elif np.allclose(state_ph, np.array([1, 1]) / np.sqrt(2)):
return None
elif np.array_equal(state_ph, np.array([1, -1]) / np.sqrt(2)):
elif np.allclose(state_ph, np.array([1, -1]) / np.sqrt(2)):
return None
raise AliceBobTranspilationException(
f'The Initialize state preparation with desired state {state} is '
Expand Down