Skip to content

nirfsg: Enable complex number support for gRPC and update system tests#2172

Open
rahur-NI wants to merge 18 commits intoni:masterfrom
rahur-NI:nirfsgGrpcComplexNumberSupport
Open

nirfsg: Enable complex number support for gRPC and update system tests#2172
rahur-NI wants to merge 18 commits intoni:masterfrom
rahur-NI:nirfsgGrpcComplexNumberSupport

Conversation

@rahur-NI
Copy link
Contributor

@rahur-NI rahur-NI commented Mar 23, 2026

  • This contribution adheres to CONTRIBUTING.md.
  • I've updated CHANGELOG.md if applicable.
  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

  • Updated numpy_read_method.py.mako template with snippets copied over from default_method.py.mako and also included gRPC generation support for numpy complex methods.
  • Updated _grpc_stub_interpreter.py.mako template to import nidevice_pb2 as grpc_complex_types only if complex numbers are used in the module.
  • Updated 'included_in_proto' in functions.py of niFake to generate the gRPC changes in functions which has complex numpy values.
  • Added grpc_server_config.json file for nirfsg to include the address and port for server listening.

List issues fixed by this Pull Request below, if any.

NA

What testing has been done?

  • Ensured the codegen modifications are as expected.
  • Added a new TestGrpc class in test_system_nirfsg.py to include gRPC-based system test session setup.
  • As the fix for a defect in nirfsg grpc-device metadata was merged recently, test_get_all_named_waveform_names test will be only passing when the next release version of grpc-device server is used for nimi-python system tests. So this test case was moved from common path to TestLibrary class in test_system_nirfsg.py file to skip being tested against grpc. This movement will be reverted once we update the grpc-device version being used later.
  • Existing system tests are passing when tested against TestLibrary and TestGrpc class included in simulated session.
  • Existing system tests are tested against hardware by keeping use_simulated_session option as False, all the nirfsg test cases are passing as expected.

@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.80%. Comparing base (448825e) to head (544dcdd).

Files with missing lines Patch % Lines
generated/nifake/nifake/_grpc_stub_interpreter.py 7.69% 12 Missing ⚠️
generated/nirfsg/nirfsg/_grpc_stub_interpreter.py 92.30% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (50.00%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2172      +/-   ##
==========================================
+ Coverage   88.76%   89.80%   +1.04%     
==========================================
  Files          73       73              
  Lines       18986    19004      +18     
==========================================
+ Hits        16853    17067     +214     
+ Misses       2133     1937     -196     
Flag Coverage Δ
codegenunittests 84.90% <ø> (ø)
nidcpowersystemtests 94.65% <ø> (+0.04%) ⬆️
nidcpowerunittests 89.53% <ø> (ø)
nidigitalsystemtests 92.26% <ø> (ø)
nidigitalunittests 68.44% <ø> (ø)
nidmmsystemtests 92.72% <ø> (ø)
nifakeunittests 85.16% <7.69%> (-0.52%) ⬇️
nifgensystemtests 94.61% <ø> (ø)
nimodinstsystemtests 73.85% <ø> (ø)
nimodinstunittests 94.20% <ø> (ø)
nirfsgsystemtests 81.19% <92.30%> (+8.16%) ⬆️
niscopesystemtests 92.94% <ø> (ø)
niscopeunittests 43.20% <ø> (ø)
nisesystemtests 91.50% <ø> (ø)
niswitchsystemtests 82.03% <ø> (ø)
nitclksystemtests 94.87% <ø> (ø)
nitclkunittests 98.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
generated/nirfsg/nirfsg/_grpc_stub_interpreter.py 78.62% <92.30%> (+78.62%) ⬆️
generated/nifake/nifake/_grpc_stub_interpreter.py 80.91% <7.69%> (-2.49%) ⬇️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 448825e...544dcdd. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +23 to +25
% if included_in_proto:
% if numpy_complex_params:
% for p in numpy_complex_params:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested conditionals, loops, etc make the code hard to read when you don't indent them.
See build\templates_library_interpreter.py\numpy_read_method.py.mako for a cleaner example.

<%
'''Renders a NotImplemented method for to the passed-in function metadata, because numpy is not supported over grpc.'''
'''Renders a GrpcStubInterpreter method for numpy write operations with complex number support.'''
Copy link
Collaborator

@ni-jfitzger ni-jfitzger Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about this comment, because the name of this file is actually numpy_read_method.py.mako‎. It's for read methods, but the write methods happen to also use it, at the moment, because they both currently just raise NotImplementedError.

It's probably time for _grpc_stub_interpreter.py/numpy_read_method.py.mako‎ and _grpc_stub_interpreter.py\numpy_write_method.py.mako to diverge, just like the library_interpreter templates.

I'm especially concerned about the changes here because you're only using it for write methods, and it may lead to bad codegen, in the future, for read methods.

@ni-jfitzger
Copy link
Collaborator

You should add new tests to src\nifake\unit_tests\test_grpc.py

@ni-jfitzger
Copy link
Collaborator

I'm worried about the system test results. We seem to have hung as soon as we reached the first nirfsg gRPC test for 32-bit. You may want to investigate on a local system.

def session_creation_kwargs(self):
return {}

def test_get_all_named_waveform_names(self, rfsg_device_session):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment about why this test was moved to TestLibrary and when it can be moved back?

raise NotImplementedError('numpy-specific methods are not supported over gRPC')
waveform_data_array_list = [
grpc_complex_types.NIComplexNumberF32(real=val.real, imaginary=val.imag)
for val in waveform_data_array.ravel()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just my imagination or is ravel not actually changing anything except for in create_deembedding_sparameter_table_array()? If so, maybe add a comment about this to the template.

Comment on lines +198 to +205
sparameter_table_list = [
grpc_complex_types.NIComplexNumber(real=val.real, imaginary=val.imag)
for val in sparameter_table.ravel()
]
self._invoke(
self._client.CreateDeembeddingSparameterTableArray,
grpc_types.CreateDeembeddingSparameterTableArrayRequest(vi=self._vi, port=port, table_name=table_name, frequencies=frequencies, sparameter_table=sparameter_table_list, number_of_ports=number_of_ports, sparameter_orientation_raw=sparameter_orientation.value),
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea if this or the other functions are correct. I'm going to lean heavily on the testing you've done and the review of @vnktshr21 , rather than wearing out my brain trying to work through it, when I don't even know what the gRPC code expects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants