Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Use record to get with keyword. #1040

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<RootNamespace>Microsoft.Quantum.Runtime</RootNamespace>
<LangVersion>10.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
24 changes: 17 additions & 7 deletions src/Simulation/Core/Submitters/SubmissionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,37 @@

#nullable enable

namespace System.Runtime.CompilerServices
{
public class IsExternalInit {}
Copy link
Contributor

Choose a reason for hiding this comment

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

As a public type, won't this conflict if another reference uses the same workaround? Can we update Microsoft.Quantum.Runtime.Core target framework to net6.0 instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tested in other places, and that type seems to be special-cased to not conflict, allowing this as a suggested workaround (as per https://developercommunity.visualstudio.com/t/error-cs0518-predefined-type-systemruntimecompiler/1244809).

}

namespace Microsoft.Quantum.Runtime.Submitters
{
/// <summary>
/// Options for a job submitted to Azure Quantum.
/// </summary>
public class SubmissionOptions
public record SubmissionOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be better to remove Default and the private constructor, and instead give each init property a default value?

{
/// <summary>
/// A name describing the job.
/// </summary>
public string FriendlyName { get; }
public string FriendlyName { get; init; }

/// <summary>
/// The number of times the program will be executed.
/// </summary>
public int Shots { get; }
public int Shots { get; init; }

/// <summary>
/// Additional target-specific parameters for the job.
/// </summary>
public ImmutableDictionary<string, string> InputParams { get; }
public ImmutableDictionary<string, string> InputParams { get; init; }

/// <summary>
/// The target capability.
/// </summary>
public string TargetCapability { get; set; }
public string TargetCapability { get; init; }

/// <summary>
/// The default submission options.
Expand Down Expand Up @@ -60,7 +65,12 @@ public SubmissionOptions With(
int? shots = null,
ImmutableDictionary<string, string>? inputParams = null,
string? targetCapability = null) =>
new SubmissionOptions(
friendlyName ?? FriendlyName, shots ?? Shots, inputParams ?? InputParams, targetCapability ?? TargetCapability);
this with
Copy link
Contributor

@bamarsha bamarsha Jun 14, 2022

Choose a reason for hiding this comment

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

I'd rather remove With, since it's redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, my only thought was to not break existing callers, but happy to go on and pull that method, then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To unblock e2e, would it be OK to mark this and Default as obsolete for now?

{
FriendlyName = friendlyName ?? FriendlyName,
Shots = shots ?? Shots,
InputParams = inputParams ?? InputParams,
TargetCapability = targetCapability ?? TargetCapability
};
}
}