Initial quantum compute and cleaning up win server.

This commit is contained in:
jmsgrogan 2023-01-09 17:31:13 +00:00
parent af50eea208
commit 5362b694e0
45 changed files with 884 additions and 429 deletions

View file

@ -1,4 +1,5 @@
add_subdirectory(circuits)
add_subdirectory(math)
add_subdirectory(machine_learning)
add_subdirectory(physics_simulation)
add_subdirectory(quantum_computing)

View file

@ -0,0 +1,12 @@
set(PLUGIN_NAME ntk_math)
list(APPEND math_HEADERS ComplexNumber.h)
list(APPEND math_LIB_INCLUDES ComplexNumber.cpp)
add_library(${PLUGIN_NAME} SHARED ${math_LIB_INCLUDES} ${math_HEADERS})
target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${PLUGIN_NAME} PUBLIC core)
set_property(TARGET ${PLUGIN_NAME} PROPERTY FOLDER plugins)
set_target_properties( ${PLUGIN_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )

View file

@ -0,0 +1,28 @@
#include "ComplexNumber.h"
ComplexNumber::ComplexNumber(double real, double imaginary)
: mReal(real),
mImaginary(imaginary)
{
}
double ComplexNumber::getReal() const
{
return mReal;
}
double ComplexNumber::getImaginary() const
{
return mImaginary;
}
void ComplexNumber::setReal(double value)
{
mReal = value;
}
void ComplexNumber::setImaginary(double value)
{
mImaginary = value;
}

View file

@ -0,0 +1,19 @@
#pragma once
class ComplexNumber
{
public:
ComplexNumber(double real = 0.0, double imaginary = 0.0);
double getReal() const;
double getImaginary() const;
void setReal(double value);
void setImaginary(double value);
private:
double mReal{ 0.0 };
double mImaginary{ 0.0 };
};

View file

@ -1,15 +1,2 @@
set(PLUGIN_NAME quantum_computing)
list(APPEND client_HEADERS
QuantumCircuit.h)
list(APPEND client_LIB_INCLUDES
QuantumCircuit.cpp)
add_library(${PLUGIN_NAME} SHARED ${client_LIB_INCLUDES})
target_include_directories(${PLUGIN_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(${PLUGIN_NAME} PUBLIC core)
set_property(TARGET ${PLUGIN_NAME} PROPERTY FOLDER plugins)
add_subdirectory(src)
add_subdirectory(test)

View file

@ -0,0 +1,12 @@
#include "BlochSphere.h"
BlochSphere::BlochSphere(const Qubit& state)
: mState(state)
{
}
const Qubit& BlochSphere::getState() const
{
return mState;
}

View file

@ -0,0 +1,13 @@
#pragma once
#include "Qubit.h"
class BlochSphere
{
public:
BlochSphere(const Qubit& state);
const Qubit& getState() const;
private:
Qubit mState;
};

View file

@ -0,0 +1,30 @@
set(PLUGIN_NAME quantum_computing)
list(APPEND quantum_computing_HEADERS
QuantumCircuit.h
BlochSphere.h
QuantumState.h
Qubit.h
QuantumGate.h
QuantumOperator.h
visuals/BlochSphereNode.h
)
list(APPEND quantum_computing_LIB_INCLUDES
QuantumCircuit.cpp
BlochSphere.cpp
QuantumState.cpp
Qubit.cpp
QuantumGate.cpp
QuantumOperator.cpp
visuals/BlochSphereNode.cpp
)
add_library(${PLUGIN_NAME} SHARED ${quantum_computing_LIB_INCLUDES} ${quantum_computing_HEADERS})
target_include_directories(${PLUGIN_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/visuals
)
target_link_libraries(${PLUGIN_NAME} PUBLIC core visual_elements ntk_math)
set_property(TARGET ${PLUGIN_NAME} PROPERTY FOLDER plugins)

View file

@ -0,0 +1,18 @@
#include "Qubit.h"
Qubit::Qubit(const ComplexNumber& alpha, const ComplexNumber& beta)
: mAlpha(alpha),
mBeta(beta)
{
}
const ComplexNumber& Qubit::getAlpha() const
{
return mAlpha;
}
const ComplexNumber& Qubit::getBeta() const
{
return mBeta;
}

View file

@ -0,0 +1,16 @@
#pragma once
#include "ComplexNumber.h"
class Qubit
{
public:
Qubit(const ComplexNumber& alpha, const ComplexNumber& beta);
const ComplexNumber& getAlpha() const;
const ComplexNumber& getBeta() const;
private:
ComplexNumber mAlpha;
ComplexNumber mBeta;
};

View file

@ -0,0 +1,40 @@
#include "BlochSphereNode.h"
#include "CircleNode.h"
BlochSphereNode::BlochSphereNode(const DiscretePoint& location)
: AbstractVisualNode(location, "BlochSphereNode")
{
}
void BlochSphereNode::setContent(BlochSphere* content)
{
mContent = content;
mContentDirty = true;
}
void BlochSphereNode::setSize(double size)
{
if (size != mSize)
{
mSize = size;
mContentDirty = true;
}
}
void BlochSphereNode::update(FontsManager* fontsManager)
{
if (!mContentDirty)
{
return;
}
mChildren.clear();
auto loc = DiscretePoint(mSize / 2.0, mSize / 2.0);
mOuterCircle = std::make_unique<CircleNode>(loc, mSize/2.0);
addChild(mOuterCircle.get());
}

View file

@ -0,0 +1,34 @@
#pragma once
#include "AbstractVisualNode.h"
#include <memory>
class BlochSphere;
class CircleNode;
class LineNode;
class BlochSphereNode : public AbstractVisualNode
{
public:
BlochSphereNode(const DiscretePoint& location);
void setContent(BlochSphere* content);
void update(FontsManager* fontsManager) override;
void setSize(double size);
private:
double mSize{ 1.0 };
bool mContentDirty{ true };
BlochSphere* mContent{ nullptr };
std::unique_ptr<CircleNode> mOuterCircle;
std::unique_ptr<CircleNode> mInnerCircle;
std::unique_ptr<CircleNode> mCentreCircle;
std::unique_ptr<CircleNode> mStateMarkerCircle;
std::unique_ptr<LineNode> mXAxis;
std::unique_ptr<LineNode> mYAxis;
std::unique_ptr<LineNode> mZAxis;
std::unique_ptr<LineNode> mStateVector;
};

View file

@ -0,0 +1,8 @@
list(APPEND UNIT_TEST_FILES
TestBlochSphereNode.cpp
)
add_executable(quantum_computing_unit_tests ${CMAKE_SOURCE_DIR}/test/test_runner.cpp ${UNIT_TEST_FILES})
target_link_libraries(quantum_computing_unit_tests PUBLIC test_utils quantum_computing)
set_property(TARGET quantum_computing_unit_tests PROPERTY FOLDER plugins)

View file

@ -0,0 +1,35 @@
#include "TestFramework.h"
#include "TestUtils.h"
#include "BlochSphereNode.h"
#include "BlochSphere.h"
#include "Scene.h"
#include "SvgConverter.h"
#include "SvgWriter.h"
#include "File.h"
TEST_CASE(TestBlochSphereNode, "quantum_computing")
{
auto node = std::make_unique<BlochSphereNode>();
Qubit state({ 1.0, 0.0 }, { 0.0, 0.0 });
auto bloch_sphere = std::make_unique<BlochSphere>(state);
node->setContent(bloch_sphere.get());
auto scene = std::make_unique<Scene>();
scene->addNode(node.get());
scene->update();
SvgConverter converter;
auto svg_document = converter.convert(scene.get());
SvgWriter writer;
auto svg_content = writer.toString(svg_document.get());
File svg_file(TestUtils::getTestOutputDir(__FILE__) / "bloch_sphere.svg");
svg_file.writeText(svg_content);
}