-
Notifications
You must be signed in to change notification settings - Fork 90
Allow reflection to find type in loaded assembly #205
Allow reflection to find type in loaded assembly #205
Conversation
bamarsha
left a comment
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.
When I try to create an IonQ machine, I get this:
Unhandled exception: System.InvalidOperationException: Sequence contains no matching element
at System.Linq.ThrowHelper.ThrowNoMatchException()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at Microsoft.Azure.Quantum.QuantumMachineFactory.CreateMachine(IWorkspace workspace, String targetName, String storageAccountConnectionString) in C:\Users\samarsha\Source\Repos\microsoft\qsharp-runtime\src\Azure\Azure.Quantum.Client\Machine\QuantumMachineFactory.cs:line 30
at Microsoft.Quantum.CsharpGeneration.EntryPointDriver.Azure.CreateMachine(AzureSettings settings) in C:\Users\samarsha\Source\Repos\microsoft\qsharp-runtime\src\Simulation\EntryPointDriver\Azure.cs:line 60
at Microsoft.Quantum.CsharpGeneration.EntryPointDriver.Azure.Submit[TIn,TOut](IEntryPoint`2 entryPoint, ParseResult parseResult, AzureSettings settings) in C:\Users\samarsha\Source\Repos\microsoft\qsharp-runtime\src\Simulation\EntryPointDriver\Azure.cs:line 28
at Microsoft.Quantum.CsharpGeneration.EntryPointDriver.Driver`3.Submit(ParseResult parseResult, AzureSettings settings) in C:\Users\samarsha\Source\Repos\microsoft\qsharp-runtime\src\Simulation\EntryPointDriver\Driver.cs:line 124
at System.CommandLine.Invocation.CommandHandler.GetResultCodeAsync(Object value, InvocationContext context)
at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__20_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass24_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__21_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseExceptionHandler>b__0>d.MoveNext()
My understanding of AppDomain.CurrentDomain.GetAssemblies() is that it only returns assemblies that have been loaded into the currently running program (e.g. a type in the assembly has been used at least once before GetAssemblies() is called). Since the IonQ assembly hasn't been used before the standalone executable needs to instantiate it, it looks like CreateMachine isn't able to find it for me.
|
Thanks for trying this out! Did you do anything special such that the existing In reply to: 414007852 [](ancestors = 414007852) |
|
No, I don't think I needed to do anything to get |
|
Could it have something to do with IQ# using signed versions of the IonQ assembly? That could mean that |
|
Below is the error I get. I'll try just specifying the PublicKeyToken and not the version; I think that should be consistent for all signed versions, but I'd need to confirm this. In reply to: 630504039 [](ancestors = 630504039) |
src/Azure/Azure.Quantum.Client/Machine/QuantumMachineFactory.cs
Outdated
Show resolved
Hide resolved
) * Create new project for entry point driver * Fix entry point option values * Add missing dashes to simulator options * Update root namespace * Add driver to nuget package * Manually add EntryPointDriver's dependencies to package * Add doc comments to Validation * Rewrite FindNuspecReferences.ps1 * Type parameterize IEntryPoint * Add reference to EntryPointDriver from tests * Remove entry point driver resources * Rename EntryPointDriver assembly * Remove unneeded generated code * Add documentation to IEntryPoint * Update Driver documentation * Enable C# nullable feature * Avoid multiple enumeration * Remove unnecessary identifier quotations * Remove "Get" prefix * Update variable name/comment * Make Validation and value parsers private/internal * Support IQArray types directly * Remove single-class namespace * Use type parameter in CreateOption * Combine some excessively separated functions * Use WithSuggestions instead of AddSuggestions * Add entry point argument tuple to interface * Fix nested tuples in arguments * Add entry point info to IEntryPoint * Add submit command * Fix typo Co-authored-by: bettinaheim <34236215+bettinaheim@users.noreply.github.com> * Use only one line for shadowing warning * Removed type parameters from IQuantumMachine interface. (#185) * Removed type parameters from IQuantumMachine interface. * Addressed Sarah's feedback. * Update src/Simulation/Core/IQuantumMachineOutput.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Use the new IQuantumMachine interface * Add TODO for histogram output * Add command-line options for Azure submission * Small code style fixes * Use real provider for Azure submission * Remove TODO from the wrong place * Use SimulatorMachine based on target name * Add option for number of shots * Validate that shots is positive * Use DefaultIfShadowed for Azure settings * Simplify adding/defaulting options * Make SimulatorOption non-static * Add AddOptionsIfAvailable method * Fix option aliases missing dashes * Disable command if required options are shadowed * Add copyright headers * Add histogram option * Make histogram pretty * Fix shadowing * Update histogram divider dash * Preserve required state of options * Simulator option is not required * Use SubmitAsync instead of ExecuteAsync * Add access token option * Rename ToWorkspace to CreateWorkspace * Remove "Azure" from option descriptions * Print job ID instead of URI for now * Add --base-uri option * Rename --access to --aad-token * Rename --id-only to --output * Add OptionInfo class * Update --shots validator message * Update --base-uri description * Add TODO for "submit" tests * Replace NotImplementedExceptions with NotSupportedExceptions * More specific TODO for number of shots * Don't include default value for required options * Hide "submit" command * Update help test * Add manifest with qsharp-runtime assemblies requiring signing (#200) (#202) * Add manifest with assemblies requiring signing * Add manifest.ps1 to build steps * Run manifest after build completes * Fix manifest.ps1 script error * Fix to manifest.ps1 * Revert unnecessary commit 466dc8c * Update TODO comments * Add test for submit help text * Add more tests for submit command * Add Microsoft.Azure.Quantum.Client sources and QuantumMachineFactory (#203) * Add Microsoft.Azure.Quantum.Client sources * Add project reference to Microsoft.Quantum.Runtime.Core * Add reference to Microsoft.Azure.Quantum.Client * Re-add missing summary start tag * Add Honeywell to QuantumMachineFactory * Allow reflection to find type in loaded assembly (#205) * Update reflection to look for signed assembly first * Use IWorkspace instead of Workspace * Catch exceptions from GetType call * Use package references to runtime components in EntryPointDriver * Revert package references to project references * Add Microsoft.Azure.Quantum.Client as NuGet dependency * Add stubs for new methods in NothingMachine * Add --dry-run option * Set shots in submission context * Add blank line before validation message * Created AzzureQuantumException. (#216) This change adds AzureQuantumException which is the base exception to throw or create new exceptions related to the Azure quantum service or storage. * Merge latest master to have access to QuantumProcessorTranslationException (#217) * Created QuantumProcessorException (#212) * Created QuantumProcessorException. * Provided a default message but added the option to supply a custom one. * Renamed to QuantumProcessorTranslationException. * Improved the default message. * Updating placeholder names to provider names (#215) Co-authored-by: Stefan J. Wernli <swernli@microsoft.com> * Show warning message for OutputFormat.FriendlyUri * Fix tests * Rename test project * Add test for unknown target * Add test project to test.ps1 * Handle Azure quantum known exceptions (#218) * Add the three standard constructors for the newly created exceptions. * Created QuantumMachineClientException and incorporated it (and other exceptions) into the standalone logic. * Removed exception that is not needed. * Improved error message. * Update src/Simulation/EntryPointDriver/Azure.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Update src/Simulation/EntryPointDriver/Azure.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Update src/Simulation/EntryPointDriver/Azure.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Update src/Simulation/EntryPointDriver/Azure.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Update copyright headers in Azure Quantum client * Remove TODO for audience URI Co-authored-by: bettinaheim <34236215+bettinaheim@users.noreply.github.com> Co-authored-by: César Zaragoza Cortés <cesar.zaragoza@outlook.com> Co-authored-by: Ryan Shaffer <ryan.shaffer@microsoft.com> Co-authored-by: Stefan J. Wernli <swernli@microsoft.com>
* Update reflection to look for signed assembly first * Use IWorkspace instead of Workspace * Catch exceptions from GetType call
) * Create new project for entry point driver * Fix entry point option values * Add missing dashes to simulator options * Update root namespace * Add driver to nuget package * Manually add EntryPointDriver's dependencies to package * Add doc comments to Validation * Rewrite FindNuspecReferences.ps1 * Type parameterize IEntryPoint * Add reference to EntryPointDriver from tests * Remove entry point driver resources * Rename EntryPointDriver assembly * Remove unneeded generated code * Add documentation to IEntryPoint * Update Driver documentation * Enable C# nullable feature * Avoid multiple enumeration * Remove unnecessary identifier quotations * Remove "Get" prefix * Update variable name/comment * Make Validation and value parsers private/internal * Support IQArray types directly * Remove single-class namespace * Use type parameter in CreateOption * Combine some excessively separated functions * Use WithSuggestions instead of AddSuggestions * Add entry point argument tuple to interface * Fix nested tuples in arguments * Add entry point info to IEntryPoint * Add submit command * Fix typo Co-authored-by: bettinaheim <34236215+bettinaheim@users.noreply.github.com> * Use only one line for shadowing warning * Removed type parameters from IQuantumMachine interface. (#185) * Removed type parameters from IQuantumMachine interface. * Addressed Sarah's feedback. * Update src/Simulation/Core/IQuantumMachineOutput.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Use the new IQuantumMachine interface * Add TODO for histogram output * Add command-line options for Azure submission * Small code style fixes * Use real provider for Azure submission * Remove TODO from the wrong place * Use SimulatorMachine based on target name * Add option for number of shots * Validate that shots is positive * Use DefaultIfShadowed for Azure settings * Simplify adding/defaulting options * Make SimulatorOption non-static * Add AddOptionsIfAvailable method * Fix option aliases missing dashes * Disable command if required options are shadowed * Add copyright headers * Add histogram option * Make histogram pretty * Fix shadowing * Update histogram divider dash * Preserve required state of options * Simulator option is not required * Use SubmitAsync instead of ExecuteAsync * Add access token option * Rename ToWorkspace to CreateWorkspace * Remove "Azure" from option descriptions * Print job ID instead of URI for now * Add --base-uri option * Rename --access to --aad-token * Rename --id-only to --output * Add OptionInfo class * Update --shots validator message * Update --base-uri description * Add TODO for "submit" tests * Replace NotImplementedExceptions with NotSupportedExceptions * More specific TODO for number of shots * Don't include default value for required options * Hide "submit" command * Update help test * Add manifest with qsharp-runtime assemblies requiring signing (#200) (#202) * Add manifest with assemblies requiring signing * Add manifest.ps1 to build steps * Run manifest after build completes * Fix manifest.ps1 script error * Fix to manifest.ps1 * Revert unnecessary commit 466dc8c * Update TODO comments * Add test for submit help text * Add more tests for submit command * Add Microsoft.Azure.Quantum.Client sources and QuantumMachineFactory (#203) * Add Microsoft.Azure.Quantum.Client sources * Add project reference to Microsoft.Quantum.Runtime.Core * Add reference to Microsoft.Azure.Quantum.Client * Re-add missing summary start tag * Add Honeywell to QuantumMachineFactory * Allow reflection to find type in loaded assembly (#205) * Update reflection to look for signed assembly first * Use IWorkspace instead of Workspace * Catch exceptions from GetType call * Use package references to runtime components in EntryPointDriver * Revert package references to project references * Add Microsoft.Azure.Quantum.Client as NuGet dependency * Add stubs for new methods in NothingMachine * Add --dry-run option * Set shots in submission context * Add blank line before validation message * Created AzzureQuantumException. (#216) This change adds AzureQuantumException which is the base exception to throw or create new exceptions related to the Azure quantum service or storage. * Merge latest master to have access to QuantumProcessorTranslationException (#217) * Created QuantumProcessorException (#212) * Created QuantumProcessorException. * Provided a default message but added the option to supply a custom one. * Renamed to QuantumProcessorTranslationException. * Improved the default message. * Updating placeholder names to provider names (#215) Co-authored-by: Stefan J. Wernli <swernli@microsoft.com> * Show warning message for OutputFormat.FriendlyUri * Fix tests * Rename test project * Add test for unknown target * Add test project to test.ps1 * Handle Azure quantum known exceptions (#218) * Add the three standard constructors for the newly created exceptions. * Created QuantumMachineClientException and incorporated it (and other exceptions) into the standalone logic. * Removed exception that is not needed. * Improved error message. * Update src/Simulation/EntryPointDriver/Azure.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Update src/Simulation/EntryPointDriver/Azure.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Update src/Simulation/EntryPointDriver/Azure.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Update src/Simulation/EntryPointDriver/Azure.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> * Update copyright headers in Azure Quantum client * Remove TODO for audience URI Co-authored-by: bettinaheim <34236215+bettinaheim@users.noreply.github.com> Co-authored-by: César Zaragoza Cortés <cesar.zaragoza@outlook.com> Co-authored-by: Ryan Shaffer <ryan.shaffer@microsoft.com> Co-authored-by: Stefan J. Wernli <swernli@microsoft.com>
Two changes to
QuantumMachineFactoryhere, to address issues I found while consuming this from IQ#:IWorkspaceparameter instead of aWorkspaceparameter.Type.GetType(), which seems to sometimes require anAssemblyQualifiedNameincluding version number and public key token in order to load the type successfully. (Open to suggestions here, in case there's a simpler way of doing this, but this seems to work.)