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
15 changes: 9 additions & 6 deletions src/Simulation/Core/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ public static Type[] GetTupleFieldTypes(this Type arg)
return op.Name;
}

// If object is an IApplyData, recursively extract arguments
if (o is IApplyData data)
{
return data.Value?.GetNonQubitArgumentsAsString();
}

// If object is a string, enclose it in quotations
if (o is string s)
{
Expand All @@ -197,6 +191,15 @@ public static Type[] GetTupleFieldTypes(this Type arg)
return (items.Any()) ? $"({string.Join(", ", items)})" : null;
}

// If object is an IApplyData, recursively extract arguments
if (o is IApplyData data)
{
if (data.Value != data)
{
return data.Value?.GetNonQubitArgumentsAsString();
}
}

// Otherwise, return argument as a string
return (o != null) ? o.ToString() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
operation TwoQubitOp (q1 : Qubit, q2 : Qubit) : Unit {
// ...
}

operation BoolArrayOp (bits : Bool[]) : Unit {
// ...
}

}
22 changes: 22 additions & 0 deletions src/Simulation/Simulators.Tests/RuntimeMetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,28 @@ public void DuplicateQubitArgs()

Assert.Equal(op.GetRuntimeMetadata(args), expected);
}

[Fact]
public void QArrayArgs()
{
var op = new QuantumSimulator().Get<Circuits.BoolArrayOp>();
IQArray<Boolean> bits = new QArray<Boolean>(new bool[] { false, true });
var args = op.__dataIn(bits);
var expected = new RuntimeMetadata()
{
Label = "BoolArrayOp",
FormattedNonQubitArgs = "[False, True]",
IsAdjoint = false,
IsControlled = false,
IsMeasurement = false,
IsComposite = false,
Children = null,
Controls = new List<Qubit>() { },
Targets = new List<Qubit>() { },
};

Assert.Equal(op.GetRuntimeMetadata(args), expected);
}
}

public class UDTTests
Expand Down
3 changes: 3 additions & 0 deletions src/Simulation/Simulators.Tests/TypeExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public void ArrayTypes()
(new FreeQubit(1), "bar"),
};
Assert.Equal("[(\"foo\"), (\"bar\")]", qTupleArr.GetNonQubitArgumentsAsString());

var qArrayBool = new QArray<Boolean>(new[] { false, true });
Assert.Equal("[False, True]", qArrayBool.GetNonQubitArgumentsAsString());
}

[Fact]
Expand Down