This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Implement GetRuntimeMetadata for ApplyIfElse variants #325
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ab799a8
Remove duplicate qubits from RuntimeMetadata.Targets
397c3b2
Use Distinct
4fd98c9
Add null check
3802bd1
First try at implementing classical controlled ops in runtimemetadata
71bd749
Implement test for ApplyIfElseR
5c58a69
Add IsConditional to equality check
6f85645
Add tests for variants
3537e0a
Fix runtimemetadata hashcode generation
6489c58
Merge branch 'master' into raphael/classical
1648d55
Avoid code duplication across ApplyIfElse variants
d56bc15
Merge branch 'main' into raphael/classical
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using Microsoft.Quantum.Simulation.Core; | ||
|
||
namespace Microsoft.Quantum.Simulation.QuantumProcessor.Extensions | ||
{ | ||
/// <summary> | ||
/// Provides interface to access base `GetRuntimeMetadata` method. | ||
/// </summary> | ||
public interface IApplyIfElse : ICallable | ||
{ | ||
theRoughCode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RuntimeMetadata? GetBaseRuntimeMetadata(IApplyData args); | ||
} | ||
|
||
/// <summary> | ||
/// Provides static `GetRuntimeMetadata` method for ApplyIfElseR and its variants | ||
/// to avoid code duplication. | ||
/// </summary> | ||
public class ApplyIfElseUtils<__C__, __T__, __U__> | ||
{ | ||
public static RuntimeMetadata? GetRuntimeMetadata(IApplyIfElse op, IApplyData args) | ||
{ | ||
Debug.Assert(args.Value is ValueTuple<Result, (__C__, __T__), (__C__, __U__)>, | ||
$"Failed to retrieve runtime metadata for {op.ToString()}."); | ||
|
||
if (args.Value is ValueTuple<Result, (__C__, __T__), (__C__, __U__)> ifArgs) | ||
{ | ||
var (result, (onZeroOp, zeroArg), (onOneOp, oneArg)) = ifArgs; | ||
var metadata = op.GetBaseRuntimeMetadata(args); | ||
|
||
if (metadata == null) return null; | ||
|
||
if (result is ResultMeasured measured) | ||
{ | ||
metadata.IsConditional = true; | ||
metadata.Controls = new List<Qubit>() { measured.Qubit }; | ||
} | ||
else | ||
{ | ||
metadata.IsComposite = true; | ||
} | ||
|
||
return metadata; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
public partial class ApplyIfElseR<__T__, __U__> : IApplyIfElse | ||
{ | ||
public RuntimeMetadata? GetBaseRuntimeMetadata(IApplyData args) => | ||
base.GetRuntimeMetadata(args); | ||
|
||
/// <inheritdoc/> | ||
public override RuntimeMetadata? GetRuntimeMetadata(IApplyData args) => | ||
ApplyIfElseUtils<ICallable, __T__, __U__>.GetRuntimeMetadata(this, args); | ||
} | ||
|
||
public partial class ApplyIfElseRA<__T__, __U__> : IApplyIfElse | ||
{ | ||
public RuntimeMetadata? GetBaseRuntimeMetadata(IApplyData args) => | ||
base.GetRuntimeMetadata(args); | ||
|
||
/// <inheritdoc/> | ||
public override RuntimeMetadata? GetRuntimeMetadata(IApplyData args) => | ||
ApplyIfElseUtils<IAdjointable, __T__, __U__>.GetRuntimeMetadata(this, args); | ||
} | ||
|
||
public partial class ApplyIfElseRC<__T__, __U__> : IApplyIfElse | ||
{ | ||
public RuntimeMetadata? GetBaseRuntimeMetadata(IApplyData args) => | ||
base.GetRuntimeMetadata(args); | ||
|
||
/// <inheritdoc/> | ||
public override RuntimeMetadata? GetRuntimeMetadata(IApplyData args) => | ||
ApplyIfElseUtils<IControllable, __T__, __U__>.GetRuntimeMetadata(this, args); | ||
} | ||
|
||
public partial class ApplyIfElseRCA<__T__, __U__> : IApplyIfElse | ||
{ | ||
public RuntimeMetadata? GetBaseRuntimeMetadata(IApplyData args) => | ||
base.GetRuntimeMetadata(args); | ||
|
||
/// <inheritdoc/> | ||
public override RuntimeMetadata? GetRuntimeMetadata(IApplyData args) => | ||
ApplyIfElseUtils<IUnitary, __T__, __U__>.GetRuntimeMetadata(this, args); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not sure I like this name/description for this.
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.
Is the name not descriptive enough or is it the description that is not clear?
This flag is
true
when the operation is an If-Else statement, likeApplyIfElseR
and will contain 2Children
(one for each measurement value).