Skip to content
Open
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
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
117 changes: 117 additions & 0 deletions clients/python/test/PredFull/test_PredFull.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from test.server_config import SERVER_GRPC, SERVER_HTTP
import tritonclient.grpc as grpcclient
import numpy as np
from pathlib import Path
import requests
import time

# To ensure MODEL_NAME == test_<filename>.py
MODEL_NAME = Path(__file__).stem.replace("test_", "")


def test_available_http():
req = requests.get(f"{SERVER_HTTP}/v2/models/{MODEL_NAME}", timeout=1)
assert req.status_code == 200


def test_available_grpc():
triton_client = grpcclient.InferenceServerClient(url=SERVER_GRPC)
assert triton_client.is_model_ready(MODEL_NAME)


def test_inference():
SEQUENCES = np.array(
[
["AA"],
["PEPTIPEPTIPEPTIPEPTIPEPTIPEPT"],
["RHKDESTNQCGPAVILMFYW"],
["RHKDESTNQCGPAVILM[UNIMOD:35]FYW"],
],
dtype=np.object_,
)
SEQUENCES_copy = SEQUENCES
for i in range(249):
for seq in SEQUENCES_copy:
SEQUENCES = np.append(SEQUENCES, [seq], axis=0)
len_s = len(SEQUENCES)

charge = np.array([[i % 6 + 1] for i in range(len_s)], dtype=np.int32)
nce = np.array([[(19 + i) % 40 + 1] for i in range(len_s)], dtype=np.float32)
fragmentation_type = np.array(
[["HCD" if i % 2 != 0 else "CID"] for i in range(len_s)], dtype=np.object_
)

start = time.time()
triton_client = grpcclient.InferenceServerClient(url=SERVER_GRPC)

in_pep_seq = grpcclient.InferInput("peptide_sequences", [len_s, 1], "BYTES")
in_pep_seq.set_data_from_numpy(SEQUENCES)

in_charge = grpcclient.InferInput("precursor_charges", [len_s, 1], "INT32")
in_charge.set_data_from_numpy(charge)

in_nce = grpcclient.InferInput("collision_energies", [len_s, 1], "FP32")
in_nce.set_data_from_numpy(nce)

in_frag = grpcclient.InferInput("fragmentation_types", [len_s, 1], "BYTES")
in_frag.set_data_from_numpy(fragmentation_type)

result = triton_client.infer(
MODEL_NAME,
inputs=[in_pep_seq, in_charge, in_nce, in_frag],
outputs=[
grpcclient.InferRequestedOutput("mzs"),
grpcclient.InferRequestedOutput("intensities"),
],
)

fragmentmz = result.as_numpy("mzs")
intensities = result.as_numpy("intensities")
end = time.time()
print(fragmentmz[0:5, :])
print(intensities[0:5, :])
print(end - start)

for i, (test_mzs, test_ints) in enumerate(
zip(
[
"AA1mzsCID20.npy",
"PEPTIPEPTIPEPTIPEPTIPEPTIPEPT2mzsHCD21.npy",
"RHKDESTNQCGPAVILMFYW3mzsCID22.npy",
"RHKDESTNQCGPAVILM(ox)FYW4mzsHCD23.npy",
],
[
"AA1intsCID20.npy",
"PEPTIPEPTIPEPTIPEPTIPEPTIPEPT2intsHCD21.npy",
"RHKDESTNQCGPAVILMFYW3intsCID22.npy",
"RHKDESTNQCGPAVILM(ox)FYW4intsHCD23.npy",
],
)
):
# get predicted arrays
pred_mzs = fragmentmz[i, :]
pred_ints = intensities[i, :]
pred_mzs = pred_mzs[pred_mzs != -1]
pred_ints = pred_ints[pred_ints != -1]
pred_ints /= 1000

# get elements in test loaded array
ground_truth_mzs = np.load("test/PredFull/numpy_arrays/" + test_mzs)
p_indices = np.where(np.isin(pred_mzs, ground_truth_mzs))[0]
gt_indices = np.where(np.isin(ground_truth_mzs, pred_mzs))[0]

print(
np.max(
abs(
pred_ints[p_indices]
- np.load("test/PredFull/numpy_arrays/" + test_ints)[gt_indices]
)
)
)
assert np.allclose(
pred_ints[p_indices],
np.load("test/PredFull/numpy_arrays/" + test_ints)[gt_indices],
rtol=0,
atol=1e-1,
equal_nan=True,
)
68 changes: 68 additions & 0 deletions clients/python/test/PredFull/test_PredFull_Postprocess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from test.server_config import SERVER_GRPC, SERVER_HTTP
from pathlib import Path
from test.lib import lib_test_available_grpc, lib_test_available_http
import numpy as np
import tritonclient.grpc as grpcclient


# To ensure MODEL_NAME == test_<filename>.py
MODEL_NAME = Path(__file__).stem.replace("test_", "")


def test_available_http():
lib_test_available_http(MODEL_NAME, SERVER_HTTP)


def test_available_grpc():
lib_test_available_grpc(MODEL_NAME, SERVER_GRPC)


def test_inference():
triton_client = grpcclient.InferenceServerClient(url=SERVER_GRPC)

spectrum = np.load("test/PredFull/numpy_arrays/HIISVMoxR2CID30_rawspectrum.npy")
in_spectrum = grpcclient.InferInput("spectrum", spectrum.shape, "FP32")
in_spectrum.set_data_from_numpy(spectrum)

mass = np.array([[871.4]], dtype=np.float32)
in_mass = grpcclient.InferInput("precursor_mass_with_oxM", [1, 1], "FP32")
in_mass.set_data_from_numpy(mass)

result = triton_client.infer(
MODEL_NAME,
inputs=[in_spectrum, in_mass],
outputs=[
grpcclient.InferRequestedOutput("mzs"),
grpcclient.InferRequestedOutput("intensities"),
],
)

mzs = result.as_numpy("mzs")
intensities = result.as_numpy("intensities")
print(mzs)
print(intensities)
print(mzs.shape)

assert intensities.shape == mzs.shape

ground_truth_intensities = np.load(
"test/PredFull/numpy_arrays/HIISVMoxR2CID30_intensities.npy"
)
ground_truth_mzs = np.load("test/PredFull/numpy_arrays/HIISVMoxR2CID30_mzs.npy")

ground_truth_mzs = ground_truth_mzs[ground_truth_intensities > 1]
ground_truth_intensities = ground_truth_intensities[ground_truth_intensities > 1]

assert np.allclose(
intensities,
ground_truth_intensities,
rtol=0,
atol=1e-4,
)

assert np.allclose(
mzs,
ground_truth_mzs,
rtol=0,
atol=1e-4,
)
73 changes: 73 additions & 0 deletions clients/python/test/PredFull/test_PredFull_Preprocess_charge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from test.server_config import SERVER_GRPC, SERVER_HTTP
from pathlib import Path
from test.lib import lib_test_available_grpc, lib_test_available_http
import numpy as np
import tritonclient.grpc as grpcclient

# To ensure MODEL_NAME == test_<filename>.py
MODEL_NAME = Path(__file__).stem.replace("test_", "")


def test_available_http():
lib_test_available_http(MODEL_NAME, SERVER_HTTP)


def test_available_grpc():
lib_test_available_grpc(MODEL_NAME, SERVER_GRPC)


def test_inference():

triton_client = grpcclient.InferenceServerClient(url=SERVER_GRPC)

charge = np.array([[3], [1]], dtype=np.int32)
in_charge = grpcclient.InferInput("precursor_charges", [len(charge), 1], "INT32")
in_charge.set_data_from_numpy(charge)

result = triton_client.infer(
MODEL_NAME,
inputs=[in_charge],
outputs=[
grpcclient.InferRequestedOutput("precursor_charges_in:0"),
],
)

one_hot_charge = result.as_numpy("precursor_charges_in:0")

ground_truth = np.array(
[
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
]
)

print(one_hot_charge[1])
assert np.array_equal(one_hot_charge[0], ground_truth)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from test.server_config import SERVER_GRPC, SERVER_HTTP
from pathlib import Path
from test.lib import lib_test_available_grpc, lib_test_available_http
import numpy as np
import tritonclient.grpc as grpcclient

# To ensure MODEL_NAME == test_<filename>.py
MODEL_NAME = Path(__file__).stem.replace("test_", "")


def test_available_http():
lib_test_available_http(MODEL_NAME, SERVER_HTTP)


def test_available_grpc():
lib_test_available_grpc(MODEL_NAME, SERVER_GRPC)


def test_inference():

triton_client = grpcclient.InferenceServerClient(url=SERVER_GRPC)

ces = np.array([[30]], dtype=np.float32)
in_ces = grpcclient.InferInput("collision_energies", [1, 1], "FP32")
in_ces.set_data_from_numpy(ces)

result = triton_client.infer(
MODEL_NAME,
inputs=[in_ces],
outputs=[
grpcclient.InferRequestedOutput("norm_collision_energy"),
],
)

normce = result.as_numpy("norm_collision_energy")

ground_truth = np.array([0.30])

assert np.allclose(normce[0], ground_truth, atol=1e-4)
Loading