-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a way to encode general functions #6788
Create a way to encode general functions #6788
Conversation
repeated float x = 1 [packed = true]; // The independent variable. | ||
repeated float y = 2 [packed = true]; // The dependent variable. | ||
|
||
// The interpolation method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide documentation for what an "interpolation method" does and how a client should evaluate the options for values?
repeated float y = 2 [packed = true]; // The dependent variable. | ||
|
||
// The interpolation method. | ||
// Currently only "interp" (i.e numpy.interp) is supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add documentation for the expected behavior of "interp"
? We should not depend on a python library (numpy
) as the description so that we are not bound to its implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
repeated float y = 2 [packed = true]; // The dependent variable. | ||
|
||
// The interpolation method. | ||
// Currently only "interp" (i.e numpy.interp) is supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's only one possible value, should we omit this field until there are other options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ommitted
@@ -431,11 +431,31 @@ message ArgMapping { | |||
repeated ArgEntry entries = 1; | |||
} | |||
|
|||
message FunctionInterpolationData { | |||
// If the function encoded has dimension `d`, then |x| = d |y|. Where |x| the length of `x`. | |||
repeated float x = 1 [packed = true]; // The independent variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, these fields are meant to evoke y = f(x)
?
Rather than calling a field x
and adding a comment to document that it's "the independent variable", WDYT of calling the field something like independent_variables
to be self-documenting? Note that the suggestion is pluralized to follow the style guidance for repeated fields: https://protobuf.dev/programming-guides/style/#repeated-fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
|
||
// Custom args are arguments that need require special processing during | ||
// deserialization. | ||
map<string, CustomArg> custom_args = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document what the string
keys in this map represent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
message InternalGate{ | ||
string name = 1; // Gate name. | ||
string module = 2; // Gate module. | ||
int32 num_qubits = 3; // Number of qubits. Required during deserialization. | ||
map<string, Arg> gate_args = 4; // Gate args. | ||
|
||
// Custom args are arguments that need require special processing during |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do gate_args
differ from custom_args
? i.e. could FunctionInterpolationData
be added to the existing Arg
to support use of the existing gate_args
? If not, is there a clear guidance (and documentation) for whether a new argument type should be an Arg
vs a CustomArg
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do gate_args differ from custom_args?
Arg
are values that we can use as is. That's after deserialization we can use that value internally. CustomArgs
are args that we need to perform extra processing on before we can use.
could FunctionInterpolationData be added to the existing Arg to support use of the existing gate_args?
no
I think if we just add an extra possiblitiy to Arg
we will just increase the complexity of (de)serialization with no obvious gain.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6788 +/- ##
=======================================
Coverage 97.85% 97.85%
=======================================
Files 1084 1084
Lines 93590 93651 +61
=======================================
+ Hits 91580 91642 +62
+ Misses 2010 2009 -1 ☔ View full report in Codecov by Sentry. |
@wcourtney ptal |
- `x` is 1D and not sorted in increasing order. | ||
- `method` is not supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a check if x
and y
have matching shapes?
- `x` is 1D and not sorted in increasing order. | |
- `method` is not supported. | |
- `x` is not sorted or has 2 or more dimensions. | |
- `y` has a different shape than `x` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use assignment instead of extend()
to set message arrays.
// The independent_var must be sorted in ascending order. | ||
// The independent_var and dependent_var must be of the same length. | ||
repeated float independent_var = 1 [packed = true]; // The independent variable. | ||
repeated float dependent_var = 2 [packed = true]; // The dependent variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies @NoureldinYosri, @wcourtney about bike-shedding, but calling these fields x_values
, y_values
, would perhaps make it a bit easier to parse what these are; it would also follow the recommended pluralization guideline.
How about
// The independent_var must be sorted in ascending order. | |
// The independent_var and dependent_var must be of the same length. | |
repeated float independent_var = 1 [packed = true]; // The independent variable. | |
repeated float dependent_var = 2 [packed = true]; // The dependent variable. | |
// The x_values must be unique and sorted in ascending order. | |
// The y_values must be of the same length as x_values. | |
repeated float x_values = 1 [packed = true]; // The x values where the function is sampled. | |
repeated float y_values = 2 [packed = true]; // The function values at the corresponding x_values. |
@@ -78,3 +101,55 @@ def _value_equality_values_(self): | |||
self._num_qubits, | |||
frozenset(self.gate_args.items()) if hashable else self.gate_args, | |||
) | |||
|
|||
|
|||
def encode_function( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name may suggest the function itself, such as np.sin, should be passed.
How about renaming to function_values_to_proto
?
If we have this one, consider adding a convenience counterpart function_values_from_proto
to extract x, y arrays.
Co-authored-by: Pavol Juhas <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
No description provided.