Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/Simulation/EntryPointDriver/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ internal static async Task<int> Simulate(
var coreAssemblyName =
(from aName in entryPoint.GetType().Assembly.GetReferencedAssemblies()
where aName.Name == "Microsoft.Quantum.QSharp.Core"
select aName).First();
var coreAssembly = Assembly.Load(coreAssemblyName.FullName);
select aName).FirstOrDefault();
var coreAssembly = coreAssemblyName != null ?
Assembly.Load(coreAssemblyName.FullName) :
null;

var resourcesEstimator = new ResourcesEstimator(coreAssembly);
await resourcesEstimator.Run<TCallable, TIn, TOut>(entryPoint.CreateArgument(parseResult));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,41 +152,43 @@ private void RegisterPrimitiveOperationsGivenAsCircuits(Assembly? coreAssembly)
var intrinsicAssembly = coreAssembly;
if (intrinsicAssembly == null)
{
intrinsicAssembly =
(from assembly in AppDomain.CurrentDomain.GetAssemblies()
where assembly.GetType("Microsoft.Quantum.Intrinsic.X") != null
select assembly).First();
var currentName = this.GetType().Assembly.GetName();
var coreName = currentName.FullName.Replace("Simulators", "QSharp.Core");
try
{
intrinsicAssembly = AppDomain.CurrentDomain.Load(coreName);
}
catch { }
}
IEnumerable<Type> primitiveOperationTypes =
from op in intrinsicAssembly.GetExportedTypes()
where op.IsSubclassOf(typeof(AbstractCallable))
select op;

if (primitiveOperationTypes.Count() == 0)
if (intrinsicAssembly != null)
{
throw new Exception("Unable to load intrinsic types. The ResourcesEstimator can only be used with the default execution target.");
}

IEnumerable<Type> primitiveOperationAsCircuits =
from op in typeof(Circuits.X).Assembly.GetExportedTypes()
where op.IsSubclassOf(typeof(AbstractCallable))
&& op.Namespace == typeof(Circuits.X).Namespace
select op;
IEnumerable<Type> primitiveOperationTypes =
from op in intrinsicAssembly.GetExportedTypes()
where op.IsSubclassOf(typeof(AbstractCallable))
select op;

foreach (Type operationType in primitiveOperationTypes)
{
IEnumerable<Type> machingCircuitTypes =
from op in primitiveOperationAsCircuits
where op.Name == operationType.Name
IEnumerable<Type> primitiveOperationAsCircuits =
from op in typeof(Circuits.X).Assembly.GetExportedTypes()
where op.IsSubclassOf(typeof(AbstractCallable))
&& op.Namespace == typeof(Circuits.X).Namespace
select op;

int numberOfMatchesFound = machingCircuitTypes.Count();
Debug.Assert(
numberOfMatchesFound <= 1,
"There should be at most one matching operation.");
if (numberOfMatchesFound == 1)
foreach (Type operationType in primitiveOperationTypes)
{
Register(operationType, machingCircuitTypes.First(), operationType.ICallableType());
IEnumerable<Type> machingCircuitTypes =
from op in primitiveOperationAsCircuits
where op.Name == operationType.Name
select op;

int numberOfMatchesFound = machingCircuitTypes.Count();
Debug.Assert(
numberOfMatchesFound <= 1,
"There should be at most one matching operation.");
if (numberOfMatchesFound == 1)
{
Register(operationType, machingCircuitTypes.First(), operationType.ICallableType());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static QCTraceSimulatorConfiguration RecommendedConfig() =>
/// Constructor used by entry point driver to provide the assembly for core types that
/// need to be overriden.
/// </summary>
public ResourcesEstimator(Assembly coreAssembly) : base(RecommendedConfig(), coreAssembly)
public ResourcesEstimator(Assembly? coreAssembly) : base(RecommendedConfig(), coreAssembly)
{
}

Expand Down