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
13 changes: 5 additions & 8 deletions MachineLearning/src/Structure.qs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ namespace Microsoft.Quantum.MachineLearning {
/// may be applied.
function NQubitsRequired(model : SequentialModel)
: Int {
mutable nQubitsRequired = 0;
mutable lastQubitIndex = -1; // Need to return 0 if there are no gates
for gate in model::Structure {
set nQubitsRequired = 1 + Fold(
MaxI, 0,
gate::ControlIndices + [
gate::TargetIndex,
nQubitsRequired
]
set lastQubitIndex = Fold(
MaxI, lastQubitIndex,
gate::ControlIndices + [gate::TargetIndex]
);
}
return nQubitsRequired;
return lastQubitIndex + 1;
}

/// # Summary
Expand Down
3 changes: 2 additions & 1 deletion MachineLearning/tests/StructureTests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Microsoft.Quantum.MachineLearning.Tests {
function NQubitsRequiredFact() : Unit {
let model = Default<ML.SequentialModel>()
w/ Structure <- [
ML.ControlledRotation((3, [7, 9]), PauliX, 0)
ML.ControlledRotation((3, [7, 9]), PauliX, 0),
ML.ControlledRotation((8, new Int[0]), PauliY, 1)
];
let actual = ML.NQubitsRequired(model);
EqualityFactI(actual, 10, "Wrong output from NQubitsRequired.");
Expand Down