ansys / ansys/pyhps

sort sorts input parameter values by string of value instead of by value

Open
#408 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
5
Forks
1
Avg merge
1d 21h
Merged PRs (30d)
9

Description

### 🔍 Before submitting the issue

- [X] I have searched among the existing issues
- [X] I am using a Python virtual environment

### 🐞 Description of the bug

during SAF development I encountered a problem with sorting in which jobs sorted by a float input parameter end up being sorted by the text value of the input parameter and not the actual float value

### 📝 Steps to reproduce

simply run the following script:

```
from pathlib import Path
from ansys.hps.client import Client, ProjectApi, JmsApi
from ansys.hps.client.jms import ( # pyright: ignore[reportMissingTypeStubs]
File,
FloatParameterDefinition,
JmsApi,
Job,
JobDefinition,
ParameterMapping,
Project,
ProjectApi,
TaskDefinition,
)
from ansys.hps.client.jms.resource.parameter_definition import ParameterDefinition # type: ignore

cl = Client(url="https://localhost:8443/hps", username="repadmin", password="repadmin")

jms_api = JmsApi(cl)
project_name = "TEST"
project_specification = Project(name=project_name, priority=1, active=True)
project = jms_api.create_project(project_specification)
id_string = str(project.id) # type: ignore
project_api = ProjectApi(cl, id_string)

file = File(name="input_file", evaluation_path="input.txt", type="text/plain", src=(Path(__file__).parent / "input.txt").as_posix())
file = project_api.create_files([file])[0]
parameter = FloatParameterDefinition(name="x")
parameter = project_api.create_parameter_definitions([parameter])[0]
parameter_mapping = ParameterMapping(key_string="x", tokenizer="=", parameter_definition_id=parameter.id, file_id=file.id)
parameter_mapping = project_api.create_parameter_mappings([parameter_mapping])[0]
task_def = TaskDefinition(name="TEST", input_file_ids=[file.id], execution_level=0)
taskdef = project_api.create_task_definitions([task_def])[0]
job_def = JobDefinition(name="JobDef", task_definition_ids=[taskdef.id], parameter_definition_ids=[parameter.id], parameter_mapping_ids=[parameter_mapping.id])
job_def = project_api.create_job_definitions([job_def])[0]
jobs = [Job(name=f"Job.{index}", values={"x" : index * 2.0}, eval_status="pending", job_definition_id=job_def.id) for index in range (0, 20)]
project_api.create_jobs(jobs=jobs)

jobs = project_api.get_jobs(sort=["values.x"])

for job in jobs:
print(f"result={job.values.get('x')}")

```
I see

```
result=0.0
result=10.0
result=12.0
result=14.0
result=16.0
result=18.0
result=2.0
result=20.0
result=22.0
result=24.0
result=26.0
result=28.0
result=30.0
result=32.0
result=34.0
result=36.0
result=38.0
result=4.0
result=6.0
result=8.0
```
input.txt is an empty file that is in the same directory as the script
### 💻 Which operating system are you using?

Windows

### 📀 Which ANSYS version are you using?

I am not using any products for this case.

HPS is running docker compose in WSL with the client running on Windows

![image](https://github.com/ansys/pyhps/assets/38562795/4d0bc68e-7dd7-4124-9d0e-195f559460d2)

### 🐍 Which Python version are you using?

3.10

### 📦 Installed packages

```shell
annotated-types==0.6.0
ansys-hps-client==0.8.0
backoff==2.2.1
certifi==2024.2.2
charset-normalizer==3.3.2
idna==3.6
# Editable install with no version control (mapdl-tyre-performance==0.1.0)
-e c:\ansysdev\mapdl_tyre_performance
marshmallow==3.21.1
marshmallow-oneofschema==3.1.1
packaging==24.0
pydantic==2.6.4
pydantic_core==2.16.3
PyJWT==2.8.0
requests==2.31.0
typing_extensions==4.10.0
urllib3==1.26.18
```

Contributor guide

Open the contributing guide

Research direction

Start with the ProjectApi.get_jobs call and its sort=["values.x"] behavior, using the reproduction script to create float-valued jobs and inspect the returned order. Trace where the values sort is requested or interpreted, then verify that numeric values sort numerically rather than as strings. Done means the reproduced sequence is numerically ordered and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.