Commit f1eedf04 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fix to staq swap shortest path to map cz to cx


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 9a05f149
FROM alpine:latest
# builds an image of 620 MB
COPY patch_Error.cpp /tmp/
COPY patch_glucose.hpp /tmp/
RUN apk add build-base gcc binutils cmake blas-dev lapack-dev python3-dev curl-dev git linux-headers py3-pip \
&& git clone --recursive https://github.com/eclipse/xacc \
&& mv /tmp/patch_Error.cpp xacc/tpls/cppmicroservices/util/src/Error.cpp \
&& mv /tmp/patch_glucose.hpp xacc/tpls/staq/libs/glucose/glucose.hpp \
&& cd xacc && mkdir build && cd build/ \
&& cmake .. && make -j4 install \
&& python3 -m pip install ipopo --user \
&& cd ../../ && rm -rf /xacc
\ No newline at end of file
/*=============================================================================
Library: CppMicroServices
Copyright (c) The CppMicroServices developers. See the COPYRIGHT
file at the top-level directory of this distribution and at
https://github.com/CppMicroServices/CppMicroServices/COPYRIGHT .
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/
#include "cppmicroservices/util/Error.h"
#include "cppmicroservices/util/String.h"
#ifdef US_PLATFORM_POSIX
#include <errno.h>
#include <string.h>
#else
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <crtdbg.h>
#endif
namespace cppmicroservices {
namespace util {
#ifdef US_PLATFORM_WINDOWS
std::string GetLastWin32ErrorStr()
{
// Retrieve the system error message for the last-error code
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
DWORD rc = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&lpMsgBuf),
0,
NULL
);
// If FormatMessage fails using FORMAT_MESSAGE_ALLOCATE_BUFFER
// it means that the size of the error message exceeds an internal
// buffer limit (128 kb according to MSDN) and lpMsgBuf will be
// uninitialized.
// Inform the caller that the error message couldn't be retrieved.
if (rc == 0)
{
return std::string("Failed to retrieve error message.");
}
std::string errMsg(ToUTF8String(std::wstring(reinterpret_cast<LPCWSTR>(lpMsgBuf))));
LocalFree(lpMsgBuf);
return errMsg;
}
#endif
std::string GetLastCErrorStr()
{
char errorString[128];
//#if ((_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE) || defined(US_PLATFORM_APPLE)
// This is the XSI strerror_r version
int en = errno;
int r = strerror_r(errno, errorString, sizeof errorString);
if (r)
{
std::string errMsg = "Unknown error " + util::ToString(en) + ": strerror_r failed with error code ";
if (r < 0)
{
errMsg += util::ToString(static_cast<int>(errno));
}
else
{
errMsg += util::ToString(r);
}
return errMsg;
}
return errorString;
//#elif defined(US_PLATFORM_WINDOWS)
// if (strerror_s(errorString, sizeof errorString, errno))
// {
// return "Unknown error";
// }
// return errorString;
//#else
// return strerror_r(errno, errorString, sizeof errorString);
//#endif
}
std::string GetExceptionStr(const std::exception_ptr& exc)
{
std::string excStr;
if (!exc)
{
return excStr;
}
try
{
std::rethrow_exception(exc);
}
catch (const std::exception& e)
{
excStr = e.what();
}
catch (...)
{
excStr = "unknown";
}
return excStr;
}
std::string GetLastExceptionStr()
{
return GetExceptionStr(std::current_exception());
}
} // namespace util
} // namespace cppmicroservices
This diff is collapsed.
......@@ -17,9 +17,18 @@
#include "xacc_service.hpp"
#include "xacc.hpp"
#include "staq_visitors.hpp"
#include "transformations/inline.hpp"
#include <regex>
// Need this to get around multiple definition error
// from upstream staq
namespace staq {
namespace transformations {
extern void desugar(staq::ast::ASTNode&);
}
}
namespace xacc {
namespace quantum {
......@@ -61,11 +70,19 @@ void SwapShort::apply(std::shared_ptr<CompositeInstruction> program,
auto staq = xacc::getCompiler("staq");
auto src = staq->translate(program);
// std::cout << "HELLO WORLD:\n" << src << "\n";
// std::cout << "HELLO WORLD:\n" << src << "\n";
// parse that to get staq ast
ast::ptr<ast::Program> prog;
try {
prog = parser::parse_string(src);
transformations::desugar(*prog);
transformations::Inliner::config c;
// Make sure we treat map all control pauli
// ops as CNOT gates
c.overrides.erase("cx");
c.overrides.erase("cy");
c.overrides.erase("cz");
transformations::inline_ast(*prog, c);
} catch (std::exception &e) {
std::stringstream ss;
ss << e.what();
......@@ -73,6 +90,7 @@ void SwapShort::apply(std::shared_ptr<CompositeInstruction> program,
xacc::error(ss.str());
}
// std::cout << "HI:\n" << *prog << "\n";
mapping::Device device(qpu->getSignature(), nQubits, adj);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment