Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/Azure/Azure.Quantum.Client/Machine/QuantumMachineFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,37 @@ public static class QuantumMachineFactory
/// <param name="targetName">The execution target for job submission.</param>
/// <param name="storageAccountConnectionString">The connection string for the Azure storage account.</param>
/// <returns>A quantum machine for job submission targeting <c>targetName</c>.</returns>
public static IQuantumMachine? CreateMachine(Workspace workspace, string targetName, string storageAccountConnectionString)
public static IQuantumMachine? CreateMachine(IWorkspace workspace, string targetName, string storageAccountConnectionString)
{
if (string.IsNullOrEmpty(targetName))
{
return null;
}

var machineName =
targetName.StartsWith("ionq.")
targetName is null
? null
: targetName.StartsWith("ionq.")
? "Microsoft.Quantum.Providers.IonQ.Targets.IonQQuantumMachine, Microsoft.Quantum.Providers.IonQ"
: targetName.StartsWith("honeywell.")
? "Microsoft.Quantum.Providers.Honeywell.Targets.HoneywellQuantumMachine, Microsoft.Quantum.Providers.Honeywell"
: null;
return machineName is null

Type machineType = null;
if (machineName != null)
{
// First try to load the signed assembly with the correct version, then try the unsigned one.
try
{
machineType = Type.GetType($"{machineName}, Version={typeof(IWorkspace).Assembly.GetName().Version}, Culture=neutral, PublicKeyToken=40866b40fd95c7f5");
}
catch
{
machineType = null;
}

machineType ??= Type.GetType(machineName, throwOnError: true);
}

return machineType is null
? null
: (IQuantumMachine)Activator.CreateInstance(
Type.GetType(machineName, throwOnError: true),
machineType,
targetName,
storageAccountConnectionString,
workspace);
Expand Down