Skip to content

Commit

Permalink
add get/destroy optim
Browse files Browse the repository at this point in the history
  • Loading branch information
relf committed Apr 14, 2020
1 parent 731ea88 commit 21e6589
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 6 deletions.
49 changes: 49 additions & 0 deletions spec/requests/api/v1/optimizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@
describe 'optimization', type: :request do
fixtures :all

path '/api/v1/optimization/{:id}' do
get 'Retrieve optimization result' do
description "Get current optimizer status and x suggestion. <br/> \
* PENDING (-1): optimizer was not asked to compute x suggestion,</br> \
* VALID (0) : valid x suggestion,</br> \
* INVALID (1) : invalid x suggestion (at least one contraint is violated),</br> \
* ERROR (2) : runtime error,</br> \
* SOLUTION (3) : known solution reached (not implemented),</br> \
* RUNNING (4) : computation in progress</br>"
tags 'Optimization'
produces 'application/json'
security [ Token: [] ]
parameter name: :id, in: :path, type: :string, description: "Optimization identifier"

response '200', "Retrieve current optimization result" do
schema type: :object,
description: "Optimization result",
properties: {
x_suggested: {
"$ref": '#components/schemas/RowVector'
},
status: {
type: :integer,
enum: [-1, 0, 1, 2, 3, 4]
},
},
required: [ :x_suggested, :status ]

let(:Authorization) { "Token FriendlyApiKey" }
let(:id) { optimization(:optimization_ackley2d).id }
run_test!
end
end
end

path '/api/v1/optimizations' do
post 'Create an optimization context' do
description "Initialize optimization context specifying design space and constraints"
Expand Down Expand Up @@ -51,6 +86,7 @@
end

path '/api/v1/optimizations/{id}' do

put 'Ask for next optimal x suggestion where f(x suggestion) is expected to be minimal' do
description "Compute next x sample point suggestion regarding provided x, y which result of previous function f evaluations <br/> \
and optional constraint functions g1, g2, ..., gn specified at optimization creation. </br> \
Expand Down Expand Up @@ -122,4 +158,17 @@
end
end

path '/api/v1/optimizations/{id}' do
delete 'Destroy optimization context' do
tags 'Optimization'
security [ Token: [] ]
parameter name: :id, in: :path, type: :string, description: "Optimization identifier"

response '200', "Optimization context successfully deleted" do
let(:id) { optimization(:optimization_ackley2d).id }
run_test!
end
end
end

end
6 changes: 3 additions & 3 deletions spec/swagger_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
minItems: 1
},
XLimits: {
description: "list of row vectors",
description: "design space (nxdim intervals)",
type: :array,
items: {
"$ref" => '#components/schemas/Doublet'
"$ref" => '#components/schemas/Interval'
},
minItems: 1
},
Doublet: {
Interval: {
type: :array,
items: {
type: :number,
Expand Down
66 changes: 63 additions & 3 deletions swagger/v1/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,49 @@ paths:
properties:
x:
"$ref": "#/components/schemas/Matrix"
"/api/v1/optimization/{:id}":
get:
summary: Retrieve optimization result
description: 'Get current optimizer status and x suggestion. <br/> * PENDING (-1):
optimizer was not asked to compute x suggestion,</br> * VALID (0)
: valid x suggestion,</br> * INVALID (1) : invalid x suggestion (at
least one contraint is violated),</br> * ERROR (2) : runtime error,</br> *
SOLUTION (3) : known solution reached (not implemented),</br> * RUNNING (4)
: computation in progress</br>'
tags:
- Optimization
security:
- Token: []
parameters:
- name: id
in: path
description: Optimization identifier
required: true
schema:
type: string
responses:
'200':
description: Retrieve current optimization results
content:
application/json:
schema:
type: object
description: Optimization result
properties:
x_suggested:
"$ref": "#components/schemas/RowVector"
status:
type: integer
enum:
- -1
- 0
- 1
- 2
- 3
- 4
required:
- x_suggested
- status
"/api/v1/optimizations":
post:
summary: Create an optimization context
Expand Down Expand Up @@ -164,6 +207,23 @@ paths:
"$ref": "#/components/schemas/Matrix"
y:
"$ref": "#/components/schemas/Matrix"
delete:
summary: Destroy optimization context
tags:
- Optimization
security:
- Token: []
parameters:
- name: id
in: path
description: Optimization identifier
required: true
schema:
type: string
responses:
'200':
description: Optimization context successfully deleted
content: {}
components:
schemas:
Error:
Expand All @@ -184,12 +244,12 @@ components:
format: double
minItems: 1
XLimits:
description: list of row vectors
description: design space (nxdim intervals)
type: array
items:
"$ref": "#components/schemas/Doublet"
"$ref": "#components/schemas/Interval"
minItems: 1
Doublet:
Interval:
type: array
items:
type: number
Expand Down

0 comments on commit 21e6589

Please sign in to comment.