Skip to content

Commit 8cfbee1

Browse files
authored
Louis/bug-fixes (#117)
* Fix undefined script property * Fix deprecation warning for bloch sphere * Remove versions from pyvenv.sh * Update missing virtual environment error message * Move warning suppression into ENCODE_IMAGE snippet * Update psvenv.ps1 Update to work the same as pyvenv.sh.
1 parent 6555a9b commit 8cfbee1

File tree

5 files changed

+20
-34
lines changed

5 files changed

+20
-34
lines changed

bin/pyvenv.ps1

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# This script sets up a Python virtual environment and installs dependencies.
66
# Note that this script is designed to be run in a Windows PowerShell environment.
77

8+
# Dependencies list.
9+
$packages = @("qiskit", "matplotlib", "pylatexenc")
10+
811
# Use Windows paths by default.
912
$venv="$((Get-Location).tostring())\venv"
1013
$python="python"
@@ -43,31 +46,21 @@ if (!(Get-Command $pip_path -errorAction SilentlyContinue)) {
4346
Exit
4447
}
4548

46-
# Dependencies list (empty value means use latest version).
47-
$packages = @{"qiskit"=""; "matplotlib"="3.3.4"; "pylatexenc"=""}
48-
4949
# Install package dependencies.
50-
foreach ($i in $packages.GetEnumerator()) {
50+
foreach ($i in $packages) {
5151
# Check if the package is installed. If no, install package.
52-
Invoke-Expression "$python_path -c `"import $($i.Name)`"" >$null 2>&1
53-
if ($LastExitCode -ne 0) {
54-
"Installing $($i.Name)..."
55-
56-
# If package requires specific version, add it to the command.
57-
if ($i.Value) {
58-
$pkg_cmd="$($i.Name)==$($i.Value)"
59-
} else {
60-
$pkg_cmd="$($i.Name)"
61-
}
52+
$cmd = Invoke-Expression "$pip_path list --disable-pip-version-check | Select-String -Pattern `"^$i `""
53+
if ($cmd -eq $null) {
54+
"Installing $i..."
6255

6356
# Install package.
64-
Invoke-Expression "$pip_path install --quiet $pkg_cmd"
57+
Invoke-Expression "$pip_path install --quiet --disable-pip-version-check $i"
6558
if ($LastExitCode -eq 0) {
66-
"Successfully installed $($i.Name)"
59+
"Successfully installed $i"
6760
} else {
68-
"Error: failed to install $($i.Name)"
61+
"Error: failed to install $i"
6962
}
7063
} else {
71-
"$($i.Name) is installed"
64+
"$i is installed"
7265
}
7366
}

bin/pyvenv.sh

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# Note that this script is designed to be run in POSIX-compatible environments
55
# which use Bash.
66

7-
# Dependencies list (empty value means use latest version).
8-
declare -A packages=(["qiskit"]="" ["matplotlib"]="3.3.4" ["pylatexenc"]="")
7+
# Dependencies list
8+
declare -a packages=("qiskit" "matplotlib" "pylatexenc")
99

1010
# Check OS for paths.
1111
venv="$PWD/venv"
@@ -51,22 +51,13 @@ if [[ ! -x "$pip_path" ]]; then
5151
fi
5252

5353
# Install package dependencies.
54-
for i in "${!packages[@]}"; do
55-
# If package requires specific version, add it to the command.
56-
if [ ! -z "${packages[$i]}" ]; then
57-
pkg_cmd="$i==${packages[$i]}"
58-
regex_cmd="^$i\s*${packages[$i]}"
59-
else
60-
pkg_cmd="$i"
61-
regex_cmd="^$i "
62-
fi
63-
54+
for i in "${packages[@]}"; do
6455
# Check if the package is installed. If no, install package.
65-
if ! "$pip_path" list --disable-pip-version-check | grep -E "$regex_cmd" &>/dev/null; then
56+
if ! "$pip_path" list --disable-pip-version-check | grep -E "^$i " &>/dev/null; then
6657
echo "Installing $i..."
6758

6859
# Install package.
69-
if "$pip_path" install --quiet --disable-pip-version-check "$pkg_cmd"; then
60+
if "$pip_path" install --quiet --disable-pip-version-check "$i"; then
7061
echo "Successfully installed $i"
7162
else
7263
echo "Error: failed to install $i"

nodes/quantum/bloch-sphere/bloch-sphere.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module.exports = function(RED) {
106106
done();
107107
}).catch((err) => {
108108
// Check if error is due to script containing a measurement
109-
if (shell.script.includes(snippets.MEASURE.toString().substring(0, 11))) {
109+
if (shell.history.join('\n').includes(snippets.MEASURE.toString().substring(0, 11))) {
110110
err = new Error(errors.BLOCH_SPHERE_WITH_MEASUREMENT);
111111
}
112112
logger.error(node.id, err);

nodes/quantum/quantum-circuit/quantum-circuit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ module.exports = function(RED) {
128128

129129
let error;
130130
if (!fileSystem.existsSync(PythonPath)) {
131-
node.warn('Python virtual environment not found - creating virtual environment. Do not close Node-RED.');
131+
node.warn('Initialising Python virtual environment. Do not close Node-RED or rerun the circuit.');
132132
logger.warn(node.id, 'Python virtual environment not found');
133133
logger.info(node.id, 'Creating virtual environment');
134134

nodes/snippets.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ const ENCODE_IMAGE =
160160
`import matplotlib.pyplot as plt
161161
import base64
162162
import io
163+
import warnings
164+
warnings.filterwarnings("ignore", category=UserWarning)
163165
buffer = io.BytesIO()
164166
plt.savefig(buffer, format='png')
165167
buffer.seek(0)

0 commit comments

Comments
 (0)