Skip to content

Commit 9ae8196

Browse files
committed
fix: pick up fix for byoc command line, add tests for it and dashdash
1 parent 8e1c22a commit 9ae8196

File tree

9 files changed

+148
-11
lines changed

9 files changed

+148
-11
lines changed

Diff for: .github/workflows/kind.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- non-gpu2/keep-it-simple
1818
- non-gpu3/keep-it-simple
1919
- non-gpu4/keep-it-simple
20+
- non-gpu5/keep-it-simple
2021
# - non-gpu1/ray-autoscaler
2122
- non-gpu1/mcad-default
2223
- non-gpu1/mcad-coscheduler

Diff for: package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: plugins/plugin-codeflare/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@types/split2": "^3.2.1"
3131
},
3232
"dependencies": {
33-
"@guidebooks/store": "^5.5.4",
33+
"@guidebooks/store": "^5.5.5",
3434
"@logdna/tail-file": "^3.0.1",
3535
"@patternfly/react-charts": "^6.94.18",
3636
"@patternfly/react-core": "^4.276.6",

Diff for: tests/kind/expected-dashdash.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
3+
const dashdash = require("yargs-parser")(require("fs").readFileSync(process.argv[2]).toString())._
4+
console.log(
5+
`['${dashdash[0]}'` + dashdash.slice(1).reduce((S, e) => S + `, '${e.replace(/^'(.+)'$/, "$1")}'`, "") + "]"
6+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import ray
2+
import numpy as np
3+
4+
from qiskit.opflow import Z, I, X
5+
from qiskit.providers.basicaer import QasmSimulatorPy
6+
from qiskit.utils import QuantumInstance
7+
from qiskit.algorithms import VQE
8+
from qiskit.circuit.library import TwoLocal
9+
from qiskit.algorithms.optimizers import SLSQP
10+
from qiskit.providers import Backend
11+
12+
import sys
13+
print(sys.argv[1:])
14+
15+
@ray.remote
16+
def prep_problem():
17+
"""Prepare demo problem."""
18+
op = (
19+
(-1.052373245772859 * I ^ I)
20+
+ (0.39793742484318045 * I ^ Z)
21+
+ (-0.39793742484318045 * Z ^ I)
22+
+ (-0.01128010425623538 * Z ^ Z)
23+
+ (0.18093119978423156 * X ^ X)
24+
)
25+
initial_state = np.random.random(8)
26+
var_form = TwoLocal(
27+
rotation_blocks="ry",
28+
entanglement_blocks="cz"
29+
)
30+
31+
return (op, var_form, initial_state)
32+
33+
@ray.remote
34+
def optimize(problem):
35+
"""Optimization demo routine."""
36+
backend = QasmSimulatorPy()
37+
38+
op, var_form, init_point = problem
39+
40+
qi = QuantumInstance(backend, seed_transpiler=42, seed_simulator=42)
41+
ansatz = TwoLocal(rotation_blocks="ry", entanglement_blocks="cz")
42+
slsqp = SLSQP(maxiter=100)
43+
44+
vqe = VQE(
45+
var_form,
46+
optimizer=slsqp,
47+
quantum_instance=qi,
48+
initial_point=init_point
49+
)
50+
result = vqe.compute_minimum_eigenvalue(op)
51+
52+
print(f"Optimization result:")
53+
print(f" - eigenvalue: {result.eigenvalue}")
54+
print(f" - optimal value: {result.optimal_value}")
55+
print(f" - optinal parameters: {result.optimal_parameters}")
56+
57+
return result
58+
59+
@ray.remote
60+
def analyze(results):
61+
"""Analyzing demo results."""
62+
return min(results, key=lambda r: r.eigenvalue.real)
63+
64+
65+
if __name__ == "__main__":
66+
with ray.init():
67+
number_of_trials = 30
68+
69+
workflow_graph = analyze.remote(
70+
results=ray.get([
71+
optimize.remote(
72+
problem=prep_problem.remote()
73+
)
74+
for _ in range(number_of_trials)
75+
])
76+
)
77+
78+
result = ray.get(workflow_graph)
79+
print(f"Final result:")
80+
print(f" - eigenvalue: {result.eigenvalue}")
81+
print(f" - optimal value: {result.optimal_value}")
82+
print(f" - optinal parameters: {result.optimal_parameters}")
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
qiskit==0.37.0

Diff for: tests/kind/profiles/non-gpu5/dashdash.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aaaaaaaaa bbbbbbbbbbbbbb 'ccccccccc ccccccccccccccc' dddddddddd eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee 'ffffffffffff ffffff' gggggggggggggggggggg

Diff for: tests/kind/profiles/non-gpu5/keep-it-simple

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "keep-it-simple",
3+
"creationTime": 1664149787016,
4+
"lastModifiedTime": 1676828268772,
5+
"lastUsedTime": 1678152542012,
6+
"choices": {
7+
"madwizard/apriori/use-gpu": "don't use gpus",
8+
"madwizard/apriori/arch": "x64",
9+
"madwizard/apriori/platform": "darwin",
10+
"madwizard/apriori/mac-installer": "Homebrew",
11+
"madwizard/apriori/in-terminal": "HTML",
12+
"ml/codeflare": "Submit a new Run",
13+
"ml/codeflare/run": "Bring Your Own Code",
14+
"ml/codeflare/training/byoc/form": "{\"Path to source\":\"$PWD/tests/kind/inputs/qiskit-with-dashdash\",\"Base image\":\"rayproject/ray:2.1.0\",\"Command line prefix\":\"python3 intentionally-not-main.py\"}",
15+
"kubernetes/choose/secret/image-pull": "No secret needed, since my image is public",
16+
"s3/choose/bucket/maybe": "My data is not stored in S3",
17+
"ml/ray/start/resources": "{\"Number of CPUs\":\"500m\",\"Number of GPUs\":\"0\",\"Minimum Workers\":\"1\",\"Maximum Workers\":\"1\",\"Worker Memory\":\"500Mi\",\"Head Memory\":\"3Gi\",\"Ephemeral Storage\":\"5Gi\"}",
18+
"kubernetes/context": "kind-codeflare-test",
19+
"kubernetes/choose/ns": "default",
20+
"ml/ray/storage/s3/maybe": "My code does not use Ray Workflows",
21+
"ml/ray/cluster/choose": "codeflare-test-ray-cluster",
22+
"ml/ray/cluster/choose/kubernetes": "codeflare-test-ray-cluster",
23+
"ml/ray/cluster/kubernetes/choose-pod-scheduler": "Keep It Simple"
24+
}
25+
}

Diff for: tests/kind/run.sh

+22-1
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,24 @@ function run {
8181
local guidebook=${2-$GUIDEBOOK}
8282
local yes=$([ -z "$FORCE_ALL" ] && [ "$FORCE" != "$profileFull" ] && [ -f "$MWPROFILES_PATH/$profile" ] && echo "--yes" || echo "")
8383

84+
local dashdashFile="$MWPROFILES_PATH_BASE"/$variant/dashdash.txt
85+
if [ -f "$dashdashFile" ]; then
86+
DASHDASH=$(cat "$dashdashFile")
87+
pushd "$SCRIPTDIR"
88+
expectedDashDash="$(node ./expected-dashdash.js "$dashdashFile")"
89+
popd
90+
echo "[Test] Run: using dashdash: $DASHDASH"
91+
echo "[Test] Run: expecting dashdash: $expectedDashDash"
92+
fi
93+
8494
local PRE="$MWPROFILES_PATH_BASE"/../profiles.d/$profile/pre
8595
if [ -f "$PRE" ]; then
8696
echo "[Test] Running pre guidebooks for profile=$profile"
8797
cat "$PRE" | xargs -n1 "$ROOT"/bin/codeflare -p $profile $yes
8898
fi
8999

90100
echo "[Test] Running with variant=$variant profile=$profile yes=$yes"
91-
GUIDEBOOK_NAME="main-job-run" "$ROOT"/bin/codeflare -p $profile $yes $guidebook | tee $OUTPUT
101+
GUIDEBOOK_NAME="main-job-run" "$ROOT"/bin/codeflare -p $profile $yes $guidebook -- $DASHDASH | tee $OUTPUT
92102
}
93103

94104
#
@@ -233,6 +243,17 @@ function test {
233243
echo "[Test] ❌ Job submit output seems incomplete: $OUTPUT"
234244
exit 1
235245
fi
246+
247+
# 5. validate dashdash if the profile being tested specifies dashdash args
248+
if [ -n "$expectedDashDash" ]; then
249+
echo "[Test] Validating dashdash handling $expectedDashDash"
250+
if grep -q "$expectedDashDash" $OUTPUT ; then
251+
echo "[Test] ✅ DashDash support seems good!"
252+
else
253+
echo "[Test] ❌ DashDash support missing, expected to find this in $OUTPUT: $DASHDASH"
254+
exit 1
255+
fi
256+
fi
236257
}
237258

238259
trap onexit INT

0 commit comments

Comments
 (0)